# -*- coding: utf-8 -*-
import os.path
import time
import random
import yaml

from src.base.ThreadDota2 import Dota2


class JiangHu(Dota2):
    def __init__(self, thread_id, name, index, public_data,ignore_block):
        super().__init__(thread_id, name, index, public_data,ignore_block)
        self.log.info("初始化父类dota2完成")
        self.data = {
            "是否修练完": False,
            "当前战功兑换层数": 0,
            "辅助兑换战功时间": 0.0,
            "最近一次小师妹时间": 0.0,
            "金轮开始时间": 0.0,
            "最近一次大还丹时间": 0.0,
            "开始跑马时间": 0.0,
            "武器装备": [],
            "开始论剑时间": 0.0,
            "黄陵层数":0,
            "当前心魔次数": 0,
            "本局开始时间":0.0,
            "龙开始时间": 0.0,
            "最近一次R宝石": 0.0,
            "辅助抽宝石时间": 0.0,
            "奇遇9前经验丹是否使用完": False,
            "奇遇次数": 0,
            "黄陵开始时间":0.0,
            "最近一次暂停时间": 0.0,
            "当前暂停次数": 0,
            "心法等级":0,
            "排行榜是否领取":False,
            "玩家楼层": 0,
            "修炼完毕": False,
        }
        self.publicData["门派挑战选择配置"] = self.dm.GetDirPath(r"pic\门派挑战")
        self.publicData["华山之巅选择配置"] = self.dm.GetDirPath(r"pic\华山之巅")
        self.publicData["心魔挑战选择配置"] = self.dm.GetDirPath(r"pic\心魔")
        self.publicData["是否掉线"] = False
        self.publicData["是否回家过"] = False
        self.publicData["是否回门派过"] = False
        self.publicData["是否打断游戏进程"] = False
        self.publicData["开始打金轮时间"] = 0.0
        # 解决鼠标悬浮到特殊位置弹框遮挡
        self.safeX = 334
        self.safeY = 672
        self.log.info("江湖初始化数据")
        self.init_data()
        self.log.info("江湖初始化数据完成")

    def init_data(self):
        self.data["轮回金轮"] = r"boss存档\金轮龙象般若功.bmp|boss存档\金轮瑜伽密乘.bmp"
        self.data["轮回"] = self.dm.GetDirPath(r"pic\boss存档")
        self.data["黄陵属性"] = self.dm.GetDirPath(r"pic\黄陵属性")
        self.data["黄陵装备"] = self.dm.GetDirPath(r"pic\黄陵装备")
        tmp_list = []
        for name in "主武器卷轴,副武器卷轴,手套卷轴,护腕卷轴,斗篷卷轴,腰带卷轴,衣服卷轴,裤子卷轴,经脉奇石,无字卷轴卷轴".split(
                ","):
            tmp_list.append(self.publicData["图片映射"][name])
        self.data["黄陵卷轴全路径"] = self.dm.GetPicAbsPath("|".join(tmp_list))
        tmp_list = []
        for name in self.publicData["存档"]["商人购买列表"].split( ","):
            tmp_list.append(self.publicData["图片映射"][name])
        self.data["商人购买路径"] = self.dm.GetPicAbsPath("|".join(tmp_list))

        self.data["背包空图片路径"] = "存档\背包空0.bmp|存档\背包空1.bmp|存档\仓库空1.bmp|存档\仓库空.bmp"
        self.data[
            "放入公共仓库图片路径"] = "存档\放入公共仓库.bmp|存档\放入公共仓库1.bmp|存档\放入公共仓库2.bmp|存档\放入公共仓库3.bmp|存档\放入公共仓库4.bmp|存档\放入公共仓库5.bmp"
        self.data["other"] = "存档\认主石不带数量.bmp|存档\功法残页不带数量.bmp|存档\锻器精华.bmp"
        self.data["宝石"] = self.dm.GetDirPath(r"pic\宝石")
        self.data["宝石优先顺序列表"] = self.LoadGemConf(r"conf\%s.yaml" % self.publicData["宝石配置"], r"宝石")
        self.data["奇遇优先顺序列表"] = self.LoadCustomConf(r"conf\%s.yaml" % self.publicData["奇遇配置"], r"奇遇")
        self.data["第一次奇遇优先顺序列表"] = self.data["奇遇优先顺序列表"][:self.publicData["奇遇重选阈值"]]

        self.data["奇遇优先顺序配置"] =  "|".join(self.data["奇遇优先顺序列表"])
        self.data["第一次奇遇优先顺序配置"] =  "|".join(self.data["第一次奇遇优先顺序列表"])

        self.data["武器开孔状态"] = [False,False,False,False,False,False]
        self.data["武器宝玉孔状态"] = [False,False,False,False,False,False]
        self.data["武器宝石孔状态"] = [False,False,False,False,False,False]

        self.data["第一次奇遇优先顺序列表新"] = self.data["奇遇优先顺序列表"][:self.publicData["奇遇选择阈值新"]]
        self.data["第一次奇遇不选顺序列表新"] = self.data["奇遇优先顺序列表"][len(self.data["奇遇优先顺序列表"])-self.publicData["奇遇不选阈值新"]:]
        self.data["奇遇优先顺序配置新"] =  "|".join(self.data["第一次奇遇优先顺序列表新"])
        self.data["第一次奇遇不选顺序配置新"] =  "|".join(self.data["第一次奇遇不选顺序列表新"])

        tmp=self.data["宝石"].split("|")
        for i in range(10):
            text="%s级"%i
            tmp_list=[x for x in tmp if text in x]
            self.data["宝石"+text] ="|".join(tmp_list)
            if i==7:
                tmp_list2=[x for x in tmp if text in x and "万古紫" not in x]
                self.data["宝石" + text+"无紫"] = "|".join(tmp_list2)
        return
    def first_init(self):
        return 0
    def run(self):
        self.log.info("游戏线程启动")
        self.first_init()
        while True:
            self.log.debug("开始查找创窗口" + self.get_main_stage())
            dota2_hwnd = self.dm.FindWindow(self.publicData["dota2_class_name"], self.publicData["dota2_tittle"])
            self.log.debug("当前游戏阶段" + self.get_main_stage())
            self.log.debug("巡检是否绑定 %s" % self.publicData["系统数据"]["巡检是否绑定"])
            self.log.info("dota2_hwnd %s " % dota2_hwnd)
            if self.publicData["系统数据"]["巡检是否绑定"] and dota2_hwnd > 0:
                self.hwnd = dota2_hwnd
                res = self.BindDOTA2Game()
                if res == 1:
                    break
            elif self.publicData["系统数据"]["巡检是否绑定"] == False or dota2_hwnd == 0:
                time.sleep(3)
                continue
        while True:
            self.log.info(self.flag)
            if self.flag == "WAIT" or self.flag == "PAUSE":
                self.log.info("game当前状态%s"%self.flag)
                time.sleep(1)
                continue
            elif self.flag == "PAUSING":
                self.log.info("game当前状态%s" % self.flag)
                self.flag = "PAUSE"
            try:
                self.log.info(time.time())
                res=self.Process()
                self.log.info(res)
                if res==1:
                    break
            except SystemExit :
                self.log.info("调用stop终止运行2")
                self.log.info(self.flag)
                if self.flag == "EXIT":
                    time.sleep(3)
                    break
            except BaseException:
                self.LogTraceback()
                break
        self.dm.UnBindWindow()

    def GoHome(self, no_wait=0,num=1,step=0.3):
        self.dm.KeyPressChar("f3", no_wait, num, step)
        self.publicData["是否回家过"] = True

    def GoSect(self,no_wait=0,num=1,step=0.3):
        self.dm.KeyPressChar("f4", no_wait, num, step)
        self.publicData["是否回门派过"] = True
    # 受限于游戏图片刷新 合成后需要暂停1s
    def SynthesisGemByLvs(self,lvs,handIn=False):
        self.log.info("合成宝石%s" % lvs)
        for lv in lvs:
            if handIn:
                self.HandInGem()
            for i in range(12):
                if i%3==0:
                    self.ClickSafe()
                    time.sleep(0.1)
                res=self.SynthesisGemByLv(lv)
                if res==0:
                    break
                else:
                    time.sleep(1)

    def SynthesisGemByLv(self,lv):
        path=self.data["宝石%s级"%lv]
        res= self.dm.FindPicExs(992, 460, 1280, 650, path, "000000", 0.95)
        if len(res)>=3:
            self.log.info(res)
            self.SynthesisGemByCoordinate(res[0][1],res[0][2])
            if len(res)>6:
                return 1
            else:
                return 0
        else:
            return 0
    # 原方法加速版
    def SynthesisGemByLvsFast(self,lvs,handIn=False):
        self.log.info("合成宝石%s" % lvs)
        for lv in lvs:
            if handIn:
                self.HandInGem()
            for i in range(12):
                if i%3==0:
                    self.ClickSafe()
                    time.sleep(0.1)
                res=self.SynthesisGemByLv(lv)
                if res==0:
                    break
                else:
                    time.sleep(1)
    def SynthesisGemByLvFast(self,lv):
        path=self.data["宝石%s级"%lv]
        res= self.dm.FindPicExs(992, 460, 1280, 650, path, "000000", 0.95)
        if len(res)>=3:
            self.log.info(res)
            self.SynthesisGemByCoordinate(res[0][1],res[0][2])
            return 1
        else:
            return 0

    def SynthesisGemByCoordinate(self,x,y):
        self.dm.RightClick(x,y,1)
        is_get = self.dm.SearchPngClick(950, 450, 1200, 680, r"存档\合成1.bmp|存档\合成2.bmp|存档\合成3.bmp|存档\合成4.bmp", 0.9, 30, 0.03, 1, 5, 5,is_wait=1)
    @staticmethod
    def GetRelativePath(path,tag=""):
        if tag=="":
            path_str = os.getcwd() + "\\"
        else:
            # path_str = os.path.join(os.getcwd(), tag) + "\\"
            path_str = os.path.join(os.getcwd(), "pic") + "\\"
        return path.replace(path_str, "")

    def GetNeedGemPath(self):
        res=[x[0] for x in self.data["宝石优先顺序列表"] if x[1]>0]
        res="|".join(res)
        return res
    def GetNeedPubGemPath(self):
        res=[x[0].replace("宝石\\","宝石\\仓库") for x in self.data["宝石优先顺序列表"]]
        res="|".join(res)
        return res
    # 上交宝石
    def HandInGem(self,path=""):
        for i in range(5):
            self.log.info(i)
            if path == "":
                pic_path = self.GetNeedGemPath()
                pic_path = self.dm.GetPicAbsPath(pic_path)
            else:
                pic_path = self.dm.GetPicAbsPath(path)
            self.log.info(self.data["宝石优先顺序列表"])
            res, x, y = self.dm.FindPicExS(992, 460, 1280, 650, pic_path, "000000", 0.9)
            if x > 0 and y > 0:
                self.dm.DragFast(x+6,y+5,1024,383)
                self.log.info("找到宝石 %s" % res)
                res=self.GetRelativePath(res,"pic")
                self.log.info("宝石相对路径 %s" % res)
                for tmp in self.data["宝石优先顺序列表"]:
                    if tmp[0]==res:
                        tmp[1]=tmp[1]-1

                self.log.info("修改后 %s"%self.data["宝石优先顺序列表"])
                time.sleep(0.3)
                # self.PutIntoPublicWarehouse(res, n=1)
            else:
                break

    def GetPublicGem(self):
        self.log.info("开始拿宝石")
        path=self.GetNeedPubGemPath()
        path = self.dm.GetPicAbsPath(path)

        for i in range(5):
            self.log.info(i)
            res, x, y = self.dm.FindPicExS(1000, 350, 1280, 450, path, "000000", 0.9)
            if x > 0 and y > 0:
                self.dm.DragFast(x+5, y+5, 1026, 556)
                self.log.info("找到宝石 %s " % res)
                res=self.GetRelativePath(res,"pic")
                self.log.info("宝石相对路径 %s " % res)
                time.sleep(0.5)
                # self.PutIntoPublicWarehouse(res, n=1)
            else:
                self.ClickSafe()
                break

    def log_stage(self):
        self.log.info("当前主要游戏阶段 %s 次要阶段 %s" % (self.publicData["系统"]["主要阶段"], self.publicData["系统"]["次要阶段"]))

    @staticmethod
    def FilterGem(data):
        result = [x[1] for x in data if x[1] >0 ]

    def MoveSafe(self):
        self.dm.MoveTo(self.safeX,self.safeY)

    def ClickSafe(self):
        self.dm.LeftClick(self.safeX,self.safeY,1)
    @staticmethod
    def LoadGemConf(path, tag,exclude=""):
        result=[]
        with open(path, "r", encoding="utf-8") as f:
            res= yaml.safe_load(f.read())
            for tmp in res:
                if tmp[1]<1:
                    continue
                else:
                    tmp[0]=r"%s\%s" % (tag, tmp[0])
                    result.append(tmp)
        return result

    def modifyStage(self, main_stage=None, second_stage=None):
        old_main_stage = self.publicData["系统"]["主要阶段"]
        old_second_stage = self.publicData["系统"]["次要阶段"]
        if main_stage is not None:
            self.log.info("修改主要阶段 %s -> %s" % (old_main_stage, main_stage))
            self.publicData["系统"]["主要阶段"] = main_stage
        if second_stage is not None:
            self.log.info("修改次要阶段 %s -> %s" % (old_second_stage, second_stage))
            self.publicData["系统"]["次要阶段"] = second_stage


    def get_second_stage(self):
        return self.publicData["系统"]["次要阶段"]

    def FastDefense(self,pause_flag=True):
        self.log.info("开始回城守家")
        self.publicData["是否回家过"] = True
        self.GoHome(no_wait=1,num=3,step=0)  # todo 此处是否要多次
        self.DotaAttack(0, 0, 640, 60)
        if pause_flag:
            self.pauseGame()
        for i in range(10):
            # 检查是否在家
            is_in = self.CheckPersonPosition(68, 660, 0.8, 1, 1, 300, 200, 800, 540)
            if is_in == 1:
                break
            else:
                self.GoHome(no_wait=1,step=0.1)
                time.sleep(0.1)
        time.sleep(0.5)
        self.DotaAttack(66, 650, 640, 20)

    # 检查大哥在线
    def CheckChiefOnline(self):
        return self.dm.SearchPngClick(40, 48, 51, 59, "dage.bmp", 0.9, 1, 0, 0, 0, 0)

    # 惊喜掉落确认
    def SurpriseDropConfirm(self):
        self.log.info("惊喜掉落确认")
        self.dm.SearchPngClick(591, 424, 711, 454,"存档\惊喜掉落确认.bmp|存档\惊喜掉落确认2.bmp|存档\惊喜掉落确认3.bmp", 0.8, 1, 0, 1, 10,10)

    def AccessNPC(self, x1, y1, x2, y2, n=3):
        is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 1, 0.1, 0, 0, 0)
        if is_get == 1:
            self.log.info("已经在npc对话页面 重新打开")
            self.dm.KeyPressChar("f1")
        for i in range(n):
            if x1!=0 and y1!=0:
                self.dm.LeftClick(x1, y1, 1)
            time.sleep(0.674)
            self.dm.LeftClick(x2, y2, 1)
            is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 10, 0.3, 0, 0, 0)
            if is_get == 1:
                time.sleep(0.1)
                return 1
        return 0

    def AccessHomeNPC(self, name, n=3,flag=True):
        self.log.info(name)
        if flag:
            self.GoSect(num=2)
            self.dm.KeyPressChar("f1", num=2)
        time.sleep(0.8)
        special=False
        if name =="战功兑换":
            path="主线\门派战功兑换.bmp"
            special=True
        elif name =="修炼":
            path="主线\门派修炼.bmp"
            special=True
        elif name =="心法":
            path="主线\门派心法.bmp"
        elif name =="奇遇":
            path="主线\门派奇遇.bmp"
            special=True
        elif name =="小师妹":
            path="主线\门派小师妹.bmp"
        elif name =="装备挑战":
            path="主线\门派装备挑战.bmp"
        elif name =="无尽挑战":
            path="主线\门派无尽挑战.bmp" # todo  被挡着
            self.DotaBlink(0,0,913,386,n=2)
            self.dm.KeyPressChar("f1", num=2)
        elif name =="文秀":
            path="主线\门派文秀.bmp"
        elif name =="请敌":
            path="主线\门派请敌.bmp"
        elif name == "挑战":
            path = "主线\门派挑战.bmp"
        elif name == "游商":
            path = "主线\门派游商.bmp"
            special=True
        else:
            return

        for i in range(n):
            is_get = self.dm.SearchPngClick(100, 20, 1100, 520, path, 0.8, 3, 0.3, 1, 25, 40)
            time.sleep(0.5)
            is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 1, 0.1, 0, 0, 0)
            if is_get == 1:
                return is_get
        if special:
            self.DotaBlink(0, 0, 639, 193, n=1)
            self.dm.KeyPressChar("f1", num=2)
            for i in range(n):
                is_get = self.dm.SearchPngClick(100, 20, 1100, 520, path, 0.8, 3, 0.3, 1, 25, 40)
                time.sleep(0.5)
                is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 1, 0.1, 0, 0, 0)
                if is_get == 1:
                    return is_get
        return 0

    # 默认c在1楼
    def AccessCarryNPC(self, name, n=3, flag=True):
        res = self.AccessSiteNPC(name, n=n, flag=flag)
        return res

        # 默认c在1楼
    def AccessSiteNPC(self, name,floor=1, n=3, flag=True):
        self.log.info(name)
        x,y=20, 686
        if flag:
            for i in range(3):
                self.dm.KeyPressChar("f1", num=2)
                is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 5, 0.0, 0, 0, 0)
                if is_get==0:
                    break
        if floor==2:
            x, y = 37, 686
        elif floor==3:
            x, y = 20, 703
        elif floor==4:
            x, y = 37, 703
        if name == "战功兑换":
            path = "主线\门派战功兑换.bmp"
            y=y-2
        elif name == "修炼":
            path = "主线\门派修炼.bmp"
            y=y-2
        elif name == "心法":
            path = "主线\门派心法.bmp"
        elif name == "奇遇":
            path = "主线\门派奇遇.bmp"
            y=y-2
        elif name == "小师妹":
            path = "主线\门派小师妹.bmp"
        elif name == "装备挑战":
            path = "主线\门派装备挑战.bmp"
        elif name == "无尽挑战":
            path = "主线\门派无尽挑战.bmp"  # todo  被挡着
            y=y+2
        elif name == "文秀":
            path = "主线\门派文秀.bmp"
        elif name == "请敌":
            path = "主线\门派请敌.bmp"
        elif name == "挑战":
            path = "主线\门派挑战.bmp"
            y=y-2
        elif name == "游商":
            path = "主线\门派游商.bmp"
        else:
            raise BaseException
        self.dm.LeftClick(x, y, 2)
        for i in range(n):
            is_get = self.dm.SearchPngClick(100, 20, 1100, 630, path, 0.8, 10, 0.1, 1, 25, 40)
            time.sleep(0.1)
            is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 5, 0.1, 0, 0, 0)
            if is_get == 1:
                return is_get
            else:
                if i == (n-1):
                    self.dm.KeyPressChar("f1",num=2)
        return 0

    def PickUp(self, x1, y1, x2, y2):
        if x1 != 0 and y1 != 0:
            self.dm.LeftClick(x1, y1, 1)
            time.sleep(0.5)
        self.dm.KeyPressChar("f2",step=0.1)
        self.dm.KeyPressChar("q",step=0.1)
        self.dm.LeftClick(x2, y2,1)
        time.sleep(0.1)
        self.dm.KeyPressChar("w",step=0.01)
        self.MoveMouseSafe()

    # 选择门派
    def ChooseSect(self):
        time.sleep(0.5)
        # sect_name_map = {
        #     "峨眉": 210, "武当": 290, "移花": 380, "少林": 460, "灵鹫": 540,
        #     "华山": "000", "五毒": 710, "丐帮": 790, "明教": 880, "唐门": 960,
        # }
        sect_name = ["峨眉", "武当", "移花", "少林", "灵鹫","华山", "五毒", "丐帮", "明教", "唐门"]
        # y = 0
        sect = self.publicData["基础配置"]["门派"].split(",")
        i=random.randint(0, len(sect)-1)
        sect=sect[i]
        if sect == "随机":
            random_int = random.randint(0, 9)
            sect = sect_name[random_int]
        if sect != "峨眉":
            path = r"存档\门派\%s.bmp" % sect
            self.dm.SearchPngClick(10, 70, 180, 520, path, 0.9, 20, 0.5, 1, 10, 5, is_wait=1)
        else:
            time.sleep(1)
        if sect == "丐帮":
            self.dm.LeftClick(691,521,2)
        time.sleep(0.5)
        if self.publicData["基础配置"]["角色装备"]=="专用":
            self.dm.LeftClick(1200, 425, 1)
        elif self.publicData["基础配置"]["角色装备"] == "通用1":
            self.dm.LeftClick(1000, 425, 1)
        elif self.publicData["基础配置"]["角色装备"] == "通用2":
            self.dm.LeftClick(1100, 425, 1)

        time.sleep(0.5)
        for i in range(1000):
            is_get = self.dm.SearchPngClick(1000, 625, 1250, 700, "开始游戏.bmp", 0.8, 1, 0, 1, 100, 15)
            if is_get == 0:
                self.modifyStage(main_stage="分解")
                break
            is_get = self.dm.SearchPngClick(125, 650, 165, 675, "f4.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get == 1:
                self.modifyStage(main_stage="分解")
                break
            time.sleep(0.1)

    # 卡会心
    def StuckBug1(self):
        self.log.info("开始卡会心")
        self.ClickSafe()
        start_time=time.time()
        for i in range(50):
            self.GoSect( no_wait=1,step=0)
            is_get = self.dm.SearchPngClick(253, 40, 826, 215, "存档\修炼.bmp", 0.9, 1, 0, 0, 0, 0)
            if is_get == 1:
                self.log.info("已成功回门派")
                break
        time.sleep(3)

        for j in range(25):
            self.log.info("j: %s" % j)
            if j == 10:
                self.dm.MoveTo(640,350)
                self.dm.KeyPressChar("a", no_wait=1,step=0.01)
                time.sleep(0.5)
            self.dm.KeyPressChar("s", no_wait=1,step=0.1)
            if time.time()-start_time>10.0:
                break
            time.sleep(0.2)

    # 卡会心
    def StuckBug1Plus(self):
        self.log.info("开始卡会心")
        for i in range(30):
            self.dm.KeyPressChar("d", no_wait=1, step=0)
            self.dm.KeyPressChar("s", no_wait=1, step=0)
            time.sleep(0.1)
        for i in range(50):
            self.dm.KeyPressChar("s", no_wait=1, step=0)
            time.sleep(0.1)

    # 奇遇9拿单
    def StuckBug2(self):
        self.log.info("开始卡丹")
        self.GoSect(num=1)
        self.publicData["是否回家过"] = False
        is_get = self.dm.SearchPngClick(75, 247, 230, 310,
                                        "主线\奇遇空白0.bmp|主线\奇遇空白1.bmp|主线\奇遇空白2.bmp|主线\奇遇空白3.bmp|主线\奇遇空白4.bmp|主线\奇遇空白5.bmp",
                                        0.95, 1, 0, 0, 0, 0)
        if is_get == 0:
            return 0
        for i in range(5):
            res=self.AccessCarryNPC("奇遇")
            if res==1:
                is_get = self.dm.SearchPngClick(469, 625, 919, 705, r"NPC选项\奇遇03.bmp", 0.95, 5, 0.3, 1, 2, 2)
                time.sleep(1)
                if self.publicData["是否回家过"] :
                    self.publicData["是否回家过"]=False
                    self.GoSect()
                    return 0
                res=self.DotaCheckMoveAttack(117, 642, 770, 375,rx=200,ry=200)
                if res==1:
                    self.log.info("成功进入奇遇3")
                    break
            time.sleep(1)
        if self.data["奇遇9前经验丹是否使用完"] is False:
            for i in range(10):
                res=self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 2, 5, 5, is_wait=1)
                if res==0:
                    self.log.info("高级经验丹使用完毕")
                    self.data["奇遇9前经验丹是否使用完"]=True
                    break
                time.sleep(0.1)
        for i in range(3):
            if self.publicData["是否回家过"]:
                self.publicData["是否回家过"] = False
                self.GoSect(num=2)
                return 0
            res=self.AccessCarryNPC("奇遇")
            if res==1:
                self.dm.SearchPngClick(469, 625, 919, 705, r"NPC选项\奇遇09.bmp", 0.95, 5, 0.3, 1, 2, 2)
                time.sleep(1)
                if self.publicData["是否回家过"] :
                    self.publicData["是否回家过"]=False
                    self.GoSect(num=2)
                    return 0
                res = self.DotaCheckMoveAttack(37, 632, 744, 400,step=0.5,n=3)
                if res==1:
                    self.log.info("成功进入奇遇9")
                    for i in range(20):
                        self.log.info(i)
                        res = self.DotaCheckMoveAttack(34, 632, 484, 447,step=0.5,n=5)
                        res = self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 2, 5, 5,
                                                     is_wait=1)
                        if res == 1:
                            self.log.info("9完毕")
                            self.GoSect(num=2)
                            return 1
                        else:
                            self.ChooseAdventureFast()

                        if self.publicData["是否回家过"]:
                            self.publicData["是否回家过"] = False
                            self.GoSect(num=2)
                            return 0
                    break

            time.sleep(1)
        return 0

    def ChooseAdventure(self):
        if self.publicData["奇遇新选法"]:
            self.ChooseAdventureNew2()
        else:
            self.ChooseAdventureNew()

    def ChooseAdventureNew(self):
        self.dm.MoveTo(1095, 90)
        self.dm.DebugScreen("奇遇\奇遇")
        self.log.info("开始选奇遇找图")
        flag =False

        for i in range(3):
            # 确保页面以显示
            res = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 60, 0.1, 0, 0, 0)
            if res ==1:
                self.GoHome()
            is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["第一次奇遇优先顺序配置"] , 0.8, 10, 0.1, 1, 20, 20)
            if is_get==1:
                flag= True
                self.GoHome()
                break
            else:
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\重新随机.bmp", 0.8, 1, 0.1, 1, 5, 5)
                if is_get==0:
                    is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["奇遇优先顺序配置"], 0.8, 5,
                                                    0.2, 1, 20, 20)
                    if is_get==0:
                        self.log.info("奇遇选择配置不全")
                    else:
                        flag=True
                    self.GoHome()
                    break

        self.log.info("结束选奇遇找图")
        if flag is False:
            self.dm.LeftClick(600, 300, 1)
            self.log.info("没找到随便选")
            self.GoHome()
        return 1
    def checkTianJi(self):
        for i in self.data["武器装备"]:
            if "天机" in i[0]:
                return True
        return False
    def ChooseAdventureNew2(self):
        self.log.info(self.data["奇遇次数"])
        self.dm.MoveTo(1095, 90)
        self.dm.DebugScreen("奇遇\奇遇")
        self.log.info("开始选奇遇找图")
        flag =True

        for i in range(5):
            # 确保页面以显示
            res = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 60, 0.1, 0, 0, 0)


            if res ==1:
                self.GoHome()
                flag = False
                have_tianji = self.checkTianJi()
                if self.publicData["主c"]["是否叠天机"] and have_tianji and self.data["奇遇次数"]< self.publicData["主c"]["叠天机次数上限"]:
                    self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 3, 0.1, 1, 5, 5)
                    time.sleep(0.5)
                    self.GoHome()
                    time.sleep(0.5)
                    res = self.DotaCheckMoveAttack(65, 667, 402, 319, rx=200, ry=200)
                    if res == 1:
                        time.sleep(3)
                    else:
                        continue

                for i in range(3):
                    is_get = self.dm.SearchPngClick(75, 247, 230, 310,
                                                    "主线\奇遇带选择问号.bmp|主线\奇遇带选择问号1.bmp|主线\奇遇带选择问号2.bmp",
                                                    0.95, 3, 0.1, 1, 2, 2)
                    if is_get != 1:
                        for i in range(2):
                            for j in range(5):
                                self.dm.LeftClick(91+31*j,261+i*31,n=1)
                    res = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 10, 0.1, 0, 0, 0)
                    if res==1:
                        break
                res = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 1, 0.1, 0, 0, 0)
                if res == 1:
                    break
            else:
                is_get = self.dm.SearchPngClick(75, 247, 230, 310,
                                                "主线\奇遇带选择问号.bmp|主线\奇遇带选择问号1.bmp|主线\奇遇带选择问号2.bmp",
                                                0.95, 1, 0.1, 1, 2, 2)


        if flag is True:
            self.log.info("结束选奇遇找图(异常)")
            self.dm.LeftClick(600, 300, 1)
            self.log.info("没找到随便选")
            self.GoHome()

        for i in range(10):
            # 确保页面以显示
            is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["奇遇优先顺序配置新"] , 0.8, 10, 0.1, 1, 20, 20)
            if is_get==1:
                time.sleep(0.1)
                flag= True
                self.GoHome()
                self.data["奇遇次数"] +=1
                self.log.info(self.data["奇遇次数"])
                break
            else:
                is_get = self.dm.SearchPngClick(501, 168, 746, 494, self.data["第一次奇遇不选顺序配置新"], 0.8, 10, 0.1,
                                                0, 0, 0)
                if is_get == 0:
                    self.dm.LeftClick(600, 300, 1)
                    flag = True
                    self.GoHome()
                    self.data["奇遇次数"] +=1
                    self.log.info(self.data["奇遇次数"])
                    break

                else:
                    is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\重新随机.bmp", 0.8, 1, 0.1, 1, 5, 5)
                    if is_get==0:
                        self.dm.LeftClick(600, 300, 1)
                        self.data["奇遇次数"] +=1
                        self.log.info(self.data["奇遇次数"])
                        break
                    else:
                        time.sleep(1)

        self.log.info("结束选奇遇找图")
        if flag is False:
            self.dm.LeftClick(600, 300, 1)
            self.log.info("没找到随便选")
            self.GoHome()
        return 1


    def ChooseAdventureFast(self):
        if self.publicData["奇遇新选法"]:
            self.ChooseAdventureNewFast2()
        else:
            self.ChooseAdventureNewFast()

    def ChooseAdventureNewFast(self):
        self.dm.MoveTo(1095, 90)
        self.dm.DebugScreen("奇遇\奇遇")
        self.log.info("开始选奇遇找图")
        flag =False

        for i in range(3):
            # 确保页面以显示
            self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 12, 0.1, 0, 0, 0)
            is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["第一次奇遇优先顺序配置"] , 0.8, 5,0.2, 1, 20, 20)
            if is_get==1:
                flag= True
                break
            else:
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\重新随机.bmp", 0.8, 1, 0.1, 1, 5, 5)
                if is_get==0:
                    is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["奇遇优先顺序配置"], 0.8, 5,
                                                    0.2, 1, 20, 20)
                    if is_get==0:
                        self.log.info("奇遇选择配置不全")
                    else:
                        flag=True
                    break

        self.log.info("结束选奇遇找图")
        if flag is False:
            self.dm.LeftClick(600, 300, 1)
            self.log.info("没找到随便选")
        return 1
    def ChooseAdventureNewFast2(self):
        self.dm.MoveTo(1095, 90)
        self.dm.DebugScreen("奇遇\奇遇")
        self.log.info("开始选奇遇找图")
        flag =False

        for i in range(3):
            # 确保页面以显示
            self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 12, 0.1, 0, 0, 0)
            is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["第一次奇遇不选顺序配置新"] , 0.8, 5,0.2, 1, 20, 20)
            if is_get==1:
                flag= True
                break
            # else:
            #     is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\重新随机.bmp", 0.8, 1, 0.1, 1, 5, 5)
            #     if is_get==0:
            #         is_get = self.dm.SearchPngClick(252, 168, 997, 494, self.data["奇遇优先顺序配置"], 0.8, 5,
            #                                         0.2, 1, 20, 20)
            #         if is_get==0:
            #             self.log.info("奇遇选择配置不全")
            #         else:
            #             flag=True
            #         break

        self.log.info("结束选奇遇找图")
        if flag is False:
            self.dm.LeftClick(600, 300, 1)
            self.log.info("没找到随便选")
        return 1
    def EatStone(self):

        self.log.error("吃石头")
        for i in range(5):
            self.dm.LeftClick(92, 24, 1)
            is_get = self.dm.SearchPngClick(40, 140, 110, 181, "存档\经脉.bmp", 0.8, 10, 0.3, 0, 0, 0)
            if is_get == 1:
                self.dm.SearchPngClick(173, 459, 1241, 665, "存档\历练任务领取奖励.bmp", 0.8, 1, 0.1, 1, 2, 5)
                break

        is_get = self.dm.SearchPngClick(40, 140, 110, 181, "存档\经脉.bmp", 0.8, 10, 0.3, 1, 5, 5)
        if is_get==1:
            time.sleep(0.5)
            self.SurpriseDropConfirm()
        self.dm.LeftClick(88, 177, 1)
        time.sleep(0.463)
        if self.publicData["基础配置"]["升级经脉石头"] == "方":
            self.dm.LeftClick(513, 256, 1)
        elif self.publicData["基础配置"]["升级经脉石头"] == "圆":
            self.dm.LeftClick(441, 331, 1)
        else:
            self.dm.LeftClick(588, 336, 1)
        time.sleep(0.863)
        # 点击升级
        self.dm.LeftClick(1134, 654, 1)
        path = "存档\白三角.bmp|存档\绿三角.bmp|存档\蓝三角.bmp|存档\紫三角.bmp|存档\绿方.bmp|存档\蓝方.bmp|存档\紫方.bmp|存档\紫圆.bmp|存档\蓝圆.bmp|存档\绿圆.bmp"
        time.sleep(0.2)
        for i in range(10):
            res=self.dm.SearchPngClick(152, 65, 900, 690, path, 0.9, 1, 0.1, 0, 0, 0)
            if res==1:
                break

        self.dm.SearchPngClick(152, 65, 900, 690, path, 0.9, 20, 0.1, 1, 27, 27, is_wait=1)
        self.dm.MoveTo(992, 639)
        time.sleep(0.5)
        self.dm.DebugScreen(r"经脉奇石\吞噬选中")
        # 吞噬
        self.dm.LeftClick(992, 639, 1)
        time.sleep(1)

        self.dm.LeftClick(90, 14, 1)
        self.dm.SearchPngClick(1220, 13, 1267, 50, "存档\存档关闭.bmp", 0.8, 1, 0.5, 1, 10, 10)

    def BuyArchiveMerchant(self):
        self.log.info("存档商人购买")
        self.AccessNPC(68, 657, 602, 541)
        time.sleep(0.207)
        self.GetShopPicPart2(tag="商人")
        if self.publicData["存档"]["是否商人购买"] is True:
            self.BuyAllGoods()
        else:
            is_get = self.dm.SearchPngClick(474, 619, 921, 707, self.data["商人购买路径"], 0.8, 12, 0.1, 2, 5, 5,is_wait=1)
        self.log.error("存档黑商人购买")
        res=self.AccessNPC(68, 657, 878, 554)
        if res==1:
            self.GetShopPicPart2(tag="黑商")
            if self.publicData["存档"]["是否黑商购买"]:
                self.BuyAllGoods()
            else:
                is_get = self.dm.SearchPngClick(474, 619, 921, 707, self.data["商人购买路径"], 0.8, 12, 0.03, 2, 5, 5,is_wait=1)

    def Challenge_Archive(self):
        self.SurpriseDropConfirm()
        is_get = self.dm.SearchPngClick(880, 525, 1075, 600, "存档\挑战存档.bmp|存档\挑战存档2.bmp", 0.8, 1, 0, 1, 10, 10)
        if is_get == 1:
            time.sleep(0.5)
            is_get = self.dm.SearchPngClick(520,45,610,72, "存档\挑战存档.bmp|存档\挑战存档2.bmp", 0.8, 1, 0, 1, 10, 10)
            if is_get == 0:
                self.modifyStage(main_stage="存档")
                self.modifyStage(second_stage="存档")
                self.publicData["开始打金轮时间"]=0.0
                return
        is_get = self.dm.SearchPngClick(500, 45 ,650, 80, "存档\游戏胜利.bmp", 0.8, 1, 0, 0,0,0)
        if is_get == 1:
            self.modifyStage(main_stage="存档")
            self.modifyStage(second_stage="存档")
            time.sleep(0.5)
            is_get = self.dm.SearchPngClick(520, 45, 610, 72, "存档\挑战存档.bmp|存档\挑战存档2.bmp", 0.8, 1, 0, 1, 10, 10)
            return
        is_get = self.dm.SearchPngClick(900, 360, 1100, 400, "存档\存档高昌迷宫.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get == 1:
            self.modifyStage(main_stage="存档")
            self.modifyStage(second_stage="存档")


    def BuyAllGoods(self, dealy=0.5):
        for i in range(10):
            self.dm.LeftClick(500 + i * 44, 679, 1)
            time.sleep(dealy)
    def BuyAllGoods2(self, dealy=0.5):
        for i in range(10):
            self.dm.LeftClick(500 + i * 44, 650, 1)
            time.sleep(dealy)
        for i in range(10):
            self.dm.LeftClick(500 + i * 44, 679, 1)
            time.sleep(dealy)
    def EquipArms(self):
        self.log.error("分解装备")
        for i in range(5):
            self.dm.LeftClick(162, 22, 1)
            is_get = self.dm.SearchPngClick(12, 85, 142, 122, "存档\装备.bmp", 0.8, 10, 0.3, 1, 5, 5)
            if is_get == 1:
                break
        for i in range(5):
            is_get = self.dm.SearchPngClick(830, 79, 902, 102, "存档\装备装备.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get==1:
                break
            else:
                self.dm.LeftClick(866,809,1)
                time.sleep(1)
        is_get = self.dm.SearchPngClick(830, 79, 902, 102, "存档\装备装备.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get != 1:
            self.log.error("分解装备异常")
            self.dm.SearchPngClick(1220, 13, 1267, 50, "存档\存档关闭.bmp", 0.8, 1, 0.5, 1, 10, 10)
            return
        # 批量分级
        self.dm.LeftClick(1052, 624, 1)
        self.dm.SearchPngClick(863, 588, 1160, 620, "存档\分解装备选择框.bmp", 0.8, 10, 0.3, 1, 10, 10, is_wait=1)
        # 确定
        self.dm.LeftClick(930, 640, 1)
        time.sleep(0.5)
        # 确认
        self.dm.LeftClick(655, 441, 1)
        self.dm.LeftClick(162, 22, 1)
        self.dm.SearchPngClick(1220, 13, 1267, 50, "存档\存档关闭.bmp", 0.8, 1, 0.5, 1, 10, 10)

    # 存在重复放入的问题  但比较没放如 更可以接受
    def PutIntoPublicWarehouse(self,path,n=3):
        path = self.dm.GetPicAbsPath(path)
        for i in range(n):
            x, y, res = self.dm.FindPic(992, 460, 1280, 650, path, "000000", 0.9)
            if x > 0 and y > 0:
                self.dm.DragFast(x+6,y+5,1024,383)
                self.MoveMouseSafe()

    def GetPublicWarehouse(self, path):
        path = self.dm.GetPicAbsPath(path)
        self.log.info("在公共库查找%s"%path)
        result=0
        for i in range(3):
            x, y, res = self.dm.FindPic(1000, 350, 1280, 450, path, "000000", 0.9)
            if x > 0 and y > 0:
                self.dm.DragFast(x+5, y+5, 1026, 556)
                self.MoveMouseSafe()
                result=1
            else:
                break
        return result

    def CheckPublicWarehouse(self, path):
        path = self.dm.GetPicAbsPath(path)
        self.log.info("在公共库查找%s"%path)
        result=0
        x, y, res = self.dm.FindPic(1000, 350, 1280, 450, path, "000000", 0.9)
        if x > 0 and y > 0:
                return 1
        return 0

    def CompetitionOnHuashan(self):
        self.SurpriseDropConfirm()

        is_get = self.dm.SearchPngClick(365, 200, 600, 300, r"华山之巅\华山之巅.bmp", 0.8, 3, 0.5,0, 0, 0)
        if is_get==1:
            for i in range(10):
                is_get=self.dm.SearchPngClick(350, 250, 900, 400,self.publicData["华山之巅选择配置"], 0.8, 10, 0.5, 1,5, 5)
                if is_get==0:
                    self.dm.LeftClick(614,345,1)
                    break
                self.dm.MoveTo(319,668)
                time.sleep(0.5)
            self.SurpriseDropConfirm()
        is_get = self.dm.SearchPngClick(500, 100, 700, 180, r"存档\挑战华山论剑.bmp|存档\挑战华山之巅.bmp", 0.8, 3,
                                        0.5, 0, 0, 0)
        if is_get == 1 and self.data["开始论剑时间"] < 150:
            # 第一次进入刷新时间
            self.data["开始论剑时间"] = time.time()
            return 0
        elif is_get == 1:
            self.log.info("论剑中")
            lun_jian_now = self.OcrLunJianNum()
            self.log.info("now论剑层数 %s" % lun_jian_now)
            self.log.info("start论剑层数 %s" % self.data["开始论剑层数"])
            self.log.info("论剑截止层数 %s" % self.publicData["存档"]["论剑截止层数"])

            if (lun_jian_now > self.data["开始论剑层数"]) and (lun_jian_now > self.publicData["存档"]["论剑截止层数"]):
                self.log.info("论剑到达层数")
                self.GoSect(num=2)
            if time.time() - self.data["开始论剑时间"] > self.publicData["存档"]["论剑时间"]:
                self.log.info("论剑超时退出")
                self.GoSect(num=2)
                time.sleep(3)
                return 1
            time.sleep(1)
        elif is_get == 0 and self.data["开始论剑时间"] < 150:
            self.log.info("去论剑")
            res = self.AccessNPC(70, 665, 636, 268)
            if res == 1:
                self.dm.LeftClick(501, 679, 1)

            self.DotaAttack(0,0,906,265)
            is_get = self.dm.SearchPngClick(500, 100, 700, 180, r"存档\挑战华山论剑.bmp|存档\挑战华山之巅.bmp", 0.8, 10,
                                            0.5, 0, 0, 0)
            if is_get ==1:
                lun_jian_start = -1
                for i in range(3):
                    time.sleep(0.3)
                    lun_jian_start=self.OcrLunJianNum()
                    if lun_jian_start != -1:
                        break
                self.log.info("论剑层数 %s" % lun_jian_start)
                self.data["开始论剑层数"] = lun_jian_start
                self.data["开始论剑时间"] = time.time()
                return 0
            else:
                return  -1
        elif is_get == 0 and self.data["开始论剑时间"] > 150:
            self.log.info("死亡或结束论剑")
            self.dm.SearchPngClick(0, 150, 30, 190, "存档\玩家信息展开.bmp", 0.8, 1, 0, 1, 10, 10)
            is_get = self.CheckChiefOnline()
            if is_get != 1:
                time.sleep(1)
            else:
                return 1
        return 0

    def AttackSmallDragon(self):
        if self.data["龙开始时间"]<150:
            res=self.JoinDragon()
            if res==1:
                self.data["龙开始时间"]=time.time()
        elif time.time()-self.data["龙开始时间"]>self.publicData["存档"]["打龙时间"]:
            self.GoHome(2)
            return 1
        else:
            is_get = self.dm.SearchPngClick(540, 130, 750, 172, "存档\龙领以屠龙.bmp|存档\龙领以屠龙2.bmp", 0.8, 1, 0,
                                            0, 0, 0,
                                            delta_color="303030")
            if is_get == 1:
                self.log.info("打小龙中")
            else:
                self.JoinDragon()
        return 0

    def AttackDragon(self):
        if self.data["龙开始时间"]<150:
            res=self.JoinDragon()
            if res==1:
                self.data["龙开始时间"]=time.time()
        else:
            is_get = self.dm.SearchPngClick(540, 130, 750, 172, "存档\龙领以屠龙.bmp|存档\龙领以屠龙2.bmp", 0.8, 1, 0,
                                            0, 0, 0, delta_color="303030")
            if is_get == 1:
                self.log.info("打小龙中")
            else:
                self.log.info("打大龙中")
                self.DaHuanDdan()
                res=self.AccessNPC(69, 669, 1004, 195)
                if res==1:
                    self.dm.LeftClick(500, 680, 1)
                    self.dm.MoveTo(500, 647)
                    is_get = self.dm.SearchPngClick(474, 470, 806, 536, "存档\副本已结束不能进入.bmp", 0.8, 3, 0.5, 3, 0, 0)
                    if is_get==1:
                        self.log.info("打大龙结束")
                        self.GoHome(2)
                        return 1
                    else:
                        self.dm.KeyPressChar("f1",num=2)
                        self.DotaAttack(0,0,640,320)
        return 0

    # 领取每日金锭
    def CollectGoldIngots(self):
        self.log.info("开始领金锭")
        self.log.info(self.index)
        if self.index%10==0:
            for i in range(10):
                self.dm.LeftClick(233,14,1)
                is_get = self.dm.SearchPngClick(495, 225, 700, 520, "主线\每周灵兽蛋.bmp", 0.8, 1, 0.5, 0, 0, 0)
                if is_get== 1:
                    break

        is_get = self.dm.SearchPngClick(230, 370, 1220, 522, "主线\每周免费领取.bmp|主线\每周免费领取2.bmp", 0.8, 10, 0.5, 1, 3, 10,is_wait=1)
        is_get = self.dm.SearchPngClick(670, 400, 800, 436, "主线\取消.bmp", 0.8, 5,
                                        0.5, 1, 3, 10, is_wait=1)
    # 无限轮回快刀老六
    def Reincarnation(self):
        for i in range(10):
            self.dm.LeftClick(125, 16, 1)
            is_get = self.dm.SearchPngClick(11, 86, 145, 145, r"主线\存档.bmp", 0.8, 1, 0.5, 2, 10, 67)
            if is_get == 1:
                break
        for i in range(10):
            self.dm.MoveTo(196, 435)
            self.dm.WheelDown(15)
            time.sleep(1)

            is_get = self.dm.SearchPngClick(200, 70, 1250, 688, self.dm.GetPicAbsPath("主线\快刀老六.bmp"),0.9,1,0.12,1,900,-30)
            if is_get >0:

                time.sleep(0.5)
                is_get = self.dm.SearchPngClick(371, 371, 460, 400, "主线\快刀老六名字.bmp", 0.8, 10, 0.1, 0, 0, 0)
                if is_get == 1:
                    is_get = self.dm.SearchPngClick(512, 531, 552, 552, r"主线\3_3.bmp", 0.8, 10, 0.1, 0, 0,0)
                    if is_get==1:
                        self.dm.LeftClick(1033, 205, 1)
                        is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 10, 0.3, 2, 5, 5)
                        time.sleep(1)
                        self.SurpriseDropConfirm()
                is_get = self.dm.SearchPngClick(750, 500, 900, 600, "主线\轮回.bmp|主线\轮回2.bmp", 0.9, 10, 0.3, 2, 5, 5)
                if is_get==1:
                    time.sleep(1)
                    is_get = self.dm.SearchPngClick(400, 230, 900, 433, "主线\快刀老六红.bmp", 0.9, 10, 0.3, 2, 5, 5)
                    if is_get<=1:
                        is_get = self.dm.SearchPngClick(400, 230, 900, 433, "主线\快刀老六金1.bmp", 0.9, 1, 0.3, 2, 5, 5)
                        if is_get<=1:
                            self.dm.LeftClick(612,322,2)


                self.dm.LeftClick(1083,177,2)
                return
            else:
                self.dm.WheelUp(25)
                time.sleep(1)

    # 领取排行榜奖励
    def GetRankingReward(self):
        if self.data["排行榜是否领取"]:
            return 1
        self.log.info("排行榜")
        start=self.GetDatetime(self.data["本局开始时间"])
        now=self.GetDatetime(time.time())
        self.log.info("排行榜111")
        while now.hour==23 and now.minute in [56,57,58,59]:
            now = self.GetDatetime(time.time())
            self.log.info("%s : %s "%(now.hour,now.minute))
            time.sleep(30)
            now = self.GetDatetime(time.time())
        self.log.info("排行榜222")
        self.log.info("%s : %s " % (now.hour, now.minute))
        if start.hour!=23 or now.hour!=0:
            self.log.info("不满足条件不领取")
            return 0
        self.log.info("排行榜333")
        if now.minute==0:
            time.sleep(30)
        for i in range(10):
            self.dm.LeftClick(276, 20, 1)
            is_get = self.dm.SearchPngClick(0, 70, 1150, 1145, r"主线\排行榜01.bmp|主线\排行榜02.bmp", 0.8, 1, 1, 0, 0, 0)
            if is_get == 1:
                break
        for i in range(5):
            self.dm.LeftClick(96, 164, 1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\领取奖励.bmp|主线\领取奖励1.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                time.sleep(1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\以领取奖励.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                break

        for i in range(5):
            self.dm.LeftClick(72, 220, 1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\领取奖励.bmp|主线\领取奖励1.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                time.sleep(1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\以领取奖励.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                break

        for i in range(5):
            self.dm.LeftClick(86, 271, 1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\领取奖励.bmp|主线\领取奖励1.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                time.sleep(1)
            is_get = self.dm.SearchPngClick(568, 627, 808, 674, r"主线\以领取奖励.bmp", 0.8, 1, 0.5, 1, 5, 5)
            if is_get == 1:
                break
        self.data["排行榜是否领取"]=True


    def ImperialMausoleuChose(self):

        if self.publicData["基础配置"]["角色"] == "主c":
            self.DaHuanDdan()
        is_get = self.dm.SearchPngClick(700, 200, 960, 430, "存档\黄陵\下一层.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get == 1:
            self.data["黄陵层数"] += 1
            res=self.HuanglingChoose()
            is_get = self.dm.SearchPngClick(700, 200, 960, 430, "存档\黄陵\下一层.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get == 1:
                # 兜底
                self.log.info("兜底")
                self.dm.LeftClick(825, 300, 2)
            if self.publicData["基础配置"]["模式"] in ["普通", "y", "侠客行", "华山之巅"]:
                self.UseAllBossSaveData()
            else:
                self.UseAllItems()
            if res==1:
                return res
            else:
                return 0
        if self.publicData["基础配置"]["角色"] == "主c":
            self.DotaAttack(94, 649, 339, 257)
        else:
            self.DotaMove(93, 649, 680, 621)

        # 大还丹
    def DaHuanDdan(self):
        if self.data["最近一次大还丹时间"] < 150.0:
            return 0
        now = time.time()
        if now - self.data["最近一次大还丹时间"] < float(self.publicData["通用"]["大还丹间隔"]):
            return 0
        self.dm.KeyPressChar("f1")
        self.dm.KeyPressChar("e")
        self.dm.KeyPressChar("r")
        self.data["最近一次大还丹时间"] = time.time()
        return 0
    def UseAllItems(self,time_out=3):
        self.log.info("使用背包全物品")
        is_get = self.dm.SearchPngClick(500, 640, 900, 720, "存档\成功退出游戏.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get == 1:
            return
        is_get = self.dm.SearchPngClick(1000,400,1200, 500, "存档\背包.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get ==0:
            self.dm.KeyPressChar("tab")
            is_get = self.dm.SearchPngClick(1000, 400, 1200, 500, "存档\背包.bmp", 0.8, 10,0.1, 0, 0, 0)
            if is_get==0:
                return 0
        start=time.time()
        for i in range(8):
            self.UseKnapsackItems(int(time.time()*1000000)%8)
            now = time.time()
            if (now-start) > time_out:
                return -1
        return 1

    def UseAllBossSaveData(self,time_out=3):
        self.log.info("使用背包全物品")
        is_get = self.dm.SearchPngClick(500, 640, 900, 720, "存档\成功退出游戏.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get == 1:
            return
        is_get = self.dm.SearchPngClick(1000,400,1200, 500, "存档\背包.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get ==0:
            self.dm.KeyPressChar("tab")
            is_get = self.dm.SearchPngClick(1000, 400, 1200, 500, "存档\背包.bmp", 0.8, 10,0.1, 0, 0, 0)
            if is_get==0:
                return 0
        start=time.time()
        for i in range(8):
            is_get = self.dm.WaitPngDisappearDiff(992, 460, 1280, 650, self.data["轮回"], 0.8, 10, 0.1, 2, 5, 5,is_wait=1)
            if is_get == 0:
                return 1
            now = time.time()
            if (now-start) > time_out:
                return -1
        return 1

    def UseKnapsackItems(self, n=0):
        self.log.info("使用背包第%s列" % (n + 1))
        for i in range(5):
            x = 1022 + n * 33
            y = 494 + i * 33
            is_get = self.dm.SearchPngClick(x - 16, y - 16, x + 16, y + 16, self.data["背包空图片路径"]+"|存档\功法残页不带数量.bmp", 0.9, 1,
                                            0, 0, 0, 0)
            if is_get != 1:
                self.log.info("点击 %s,%s" % (x, y))
                self.dm.LeftClick(x, y, 2)
            else:
                self.log.info("跳过点击 %s,%s" % (x, y))
    def JoinDock(self):
        self.log.info("进船坞")
        for i in range(10):
            if self.publicData["基础配置"]["角色"] != "主c":
                self.GoHome( num=30, step=0.1)
                time.sleep(1)
            self.AccessNPC(73, 664, 740, 449)
            self.dm.LeftClick(500, 680, 1)
            time.sleep(1)
            if self.publicData["基础配置"]["角色"] == "主c":
                is_get = self.DotaCheckMoveAttack(56, 685, 800, 400,step=1,n=10)
                if is_get == 1:
                    self.publicData["系统数据"]["船坞次数"] += 1
                    self.publicData["是否进船坞"] = 1
                    return 1
            else:
                is_get = self.DotaCheckMoveAttack(56, 685, 650, 209, 400,step=1,n=10)
                if is_get == 1:
                    self.publicData["系统数据"]["船坞次数"] += 1
                    self.publicData["是否进船坞"] = 1
                    return 1
        return 0

    # 不易区分大哥辅助 但辅助进前要判断
    def JoinDragon(self):
        self.log.info("进龙")
        for i in range(10):
            self.AccessNPC(69, 669, 1004, 195)
            self.dm.LeftClick(500, 680, 1)

            is_get = self.dm.SearchPngClick(540,130,750,172, "存档\龙领以屠龙.bmp|存档\龙领以屠龙2.bmp", 0.8, 1, 0, 0, 0, 0,
                                            delta_color="303030")
            if is_get==1:
                return 1
        return 0

    def JoinDockAndFusang(self):
        self.log.info("进船坞&扶桑")
        mode=""
        for i in range(5):
            if self.publicData["系统"]["主要阶段"] in ["存档等待","退出游戏"]:
                break
            if self.publicData["基础配置"]["角色"] != "主c":
                self.GoHome(num=30, step=0.1)
                time.sleep(1)
                res=self.WaitePauseEnd()
                if res==1:
                    time.sleep(random.randint(1,10))
                    continue
            res=self.AccessNPC(73, 664, 740, 449)
            if res == 1:
                is_get = self.dm.SearchPngClick(300, 680, 500, 710,r"存档\NPC船坞.bmp|存档\NPC船坞2.bmp", 0.9, 1,
                                                0, 0, 0, 0)
                if is_get==1:
                    mode="船坞"
                else:
                    is_get = self.dm.SearchPngClick(300, 680, 500, 710, r"存档\NPC扶桑.bmp|存档\NPC扶桑2.bmp", 0.9, 1,
                                                    0, 0, 0, 0)
                    if is_get==1:
                        mode = "扶桑"

            self.dm.LeftClick(500, 680, 1)
            time.sleep(1)
            self.log.info(mode)
            if mode=="船坞":
                if self.publicData["基础配置"]["角色"] == "主c":
                    is_get = self.DotaCheckMoveAttack(56, 685, 800, 400, step=1, n=10)
                    if is_get == 1:
                        self.publicData["系统数据"]["船坞次数"] += 1
                        self.publicData["是否进船坞"] = 1
                        return 1
                else:
                    is_get = self.DotaCheckMoveAttack(56, 685, 650, 209, step=1, n=10)
                    if is_get == 1:
                        self.publicData["系统数据"]["船坞次数"] += 1
                        self.publicData["是否进船坞"] = 1
                        return 1
            else:
                if self.publicData["基础配置"]["角色"] == "主c":
                    return 1 # todo
                else:
                    is_get = self.DotaCheckMoveAttack(56, 688, 917, 128, step=1, n=10)
                    if is_get == 1:
                        self.publicData["系统数据"]["船坞次数"] += 1
                        self.publicData["是否进船坞"] = 1
                        return 1

        return 0

    def JoinGaoChangX(self):
        self.log.info("进存档高昌")

        for i in range(5):
            if self.publicData["系统"]["主要阶段"] in ["存档等待","退出游戏"]:
                break

            res = self.AccessNPC(70, 662, 638, 319)
            if res == 1:
                self.dm.LeftClick(500, 680, 1)
                time.sleep(1)
                is_get = self.DotaCheckMoveAttack(18, 643, 800, 400, step=1, n=10)
                if is_get == 1:
                        self.publicData["系统数据"]["高昌次数"] += 1
                        self.publicData["是否进存档高昌"] = 1 # 目前没用
                        return 1

        return 0
    def DelayingEnemy(self):
        if self.data["当前暂停次数"] >= self.publicData["主c"]["暂停次数"]:
            return 0
        if self.data["最近一次暂停时间"] < 150.0:
            return 0
        now = time.time()
        if now - self.data["最近一次暂停时间"] < 700.0:
            return 0
        if self.publicData["系统"]["主要阶段"] =="存档":
            self.data["最近一次暂停时间"] = time.time()+99999.0
            return
        self.log.info("开始暂停")
        is_get=self.AccessNPC(68, 662,589, 404)

        is_get = self.dm.SearchPngClick(474, 619, 921, 707, r"主线\拖延敌军.bmp", 0.8, 5, 0.1, 2, 5, 5, is_wait=1)
        is_get2 = self.dm.SearchPngClick(474, 619, 921, 707, r"主线\拖延敌军.bmp", 0.8, 1, 0.1, 2, 5, 5)

        if is_get==1 and is_get2==0:
            self.data["最近一次暂停时间"]=time.time()
            self.data["当前暂停次数"] +=1
            return 1
        elif is_get==0 and is_get2==0:
            self.data["最近一次暂停时间"]+=30.0

        return 0

    def CheckMode(self):
        for i in range(10):
            res = self.AccessNPC(73, 664, 740, 449)
            if res == 1:
                is_get = self.dm.SearchPngClick(300, 680, 500, 710, r"存档\NPC扶桑.bmp|存档\NPC扶桑2.bmp", 0.9, 1,
                                                0, 0, 0, 0)
                if is_get == 1:
                    return "异国志"
                is_get = self.dm.SearchPngClick(300, 680, 500, 710, r"存档\NPC船坞.bmp|存档\NPC船坞2.bmp", 0.9, 1,
                                                0, 0, 0, 0)
                if is_get == 1:
                    # 普通一样不做区分
                    break
        for i in range(10):
            res = self.AccessNPC(70, 665, 636, 268)
            if res == 1:
                is_get = self.dm.SearchPngClick(300, 680, 500, 710, r"存档\NPC华山之巅.bmp|存档\NPC华山之巅2.bmp", 0.9, 1,
                                                0, 0, 0, 0)
                if is_get == 1:

                    return "华山之巅"

                is_get = self.dm.SearchPngClick(300, 680, 500, 710, r"存档\NPC华山论剑.bmp|存档\NPC华山论剑2.bmp", 0.9, 1,
                                                0, 0, 0, 0)
                if is_get == 1:
                    # 普通一样不做区分
                    return "侠客行"

        return ""

    def SwitchQSkill(self,n):
        self.log.info("开始切换技能%s"%n)
        # 不切换
        if n==0:
            return 0
        self.dm.KeyPressChar("f1",num=2)
        is_get = self.dm.SearchPngClick(437, 626, 456, 643, r"主线\q切换图标.bmp", 0.9, 2, 1, 1, 2,2)
        time.sleep(1)
        if is_get==1:
            if n==1:
                self.dm.LeftClick(415, 589, n=2)
            elif n==2:
                self.dm.LeftClick(452,589,n=2)
            elif n==3:
                # 如果该门派只有2个技能则 依然选第二个
                self.dm.LeftClick(475,589,n=2)

            return 1
        else:
            return 0

    # 战功兑换层数
    def ExchangeMilitaryAchievements(self,n,isGoHome=True):
        if self.data["当前战功兑换层数"]>n:
            return 1
        if isGoHome:
            self.log.info("开始战功兑换")
            is_get=self.AccessHomeNPC("战功兑换")
        else:
            is_get = self.AccessCarryNPC("战功兑换")
        if is_get>0:
            time.sleep(0.2)
            path = r"存档\战功兑换\第1层0.bmp|存档\战功兑换\第1层1.bmp|存档\战功兑换\第2层0.bmp|存档\战功兑换\第3层0.bmp|存档\战功兑换\第3层1.bmp|存档\战功兑换\第4层0.bmp|存档\战功兑换\第5层0.bmp|存档\战功兑换\第6层0.bmp|存档\战功兑换\第6层1.bmp|存档\战功兑换\第7层0.bmp|存档\战功兑换\第7层1.bmp|存档\战功兑换\第7层2.bmp|存档\战功兑换\第7层3.bmp"
            path = self.dm.GetPicAbsPath(path)
            x, y, res = self.dm.FindPic(475, 651, 919, 704, path, "000000", 0.9, 0)
            if res > n:
                self.data["当前战功兑换层数"]=res
                self.log.info("战功兑换结束")
                return 1
            if res==-1 and self.publicData["基础配置"]["模式"]=="普通":
                is1=self.dm.SearchPngClick(336, 400, 470, 712, r"存档\战功兑换头像.bmp", 0.9, 0, 0, 0, 0, 0)
                is2=self.dm.SearchPngClick(474, 650, 921, 701, r"存档\npc空白.bmp", 0.95, 0, 0, 0, 0, 0)
                if is1==1 and is2==1:
                    self.data["当前战功兑换层数"] = 9
                    return 1
            self.data["当前战功兑换层数"] = res
            self.log.info("当前战功兑换层数%s"%res)
            if res in [0,1]:

                path1 = r"存档\战功兑换\11.bmp|存档\战功兑换\12.bmp|存档\战功兑换\13.bmp|存档\战功兑换\14.bmp|存档\战功兑换\15.bmp|存档\战功兑换\16.bmp|存档\战功兑换\17.bmp"
                path2=r"存档\战功兑换\18.bmp"
                for i in range(9):
                    is_get = self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 0, 0.1, 0, 0, 0)
                    if is_get == 1:
                        return res
                    self.MoveSafe()
                    self.log.info(i)
                    is_get = self.dm.SearchPngClick(405, 330, 885, 475,
                                                    "主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp|主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp|主线\洗髓经_垃圾.bmp|主线\洗髓经_垃圾2.bmp",
                                                    0.95, 1, 0, 1, 5, 5)
                    result=self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 2, 0.052, 6, 10, 10, is_wait=1)
                    if result==0:
                        self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 10, 0.052, 6, 10, 10, is_wait=1)
                        break

            elif res == 2:
                path = r"存档\战功兑换\26.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 6, 0.052, 6, 10, 10, is_wait=1)
            elif res in [3,4]:
                path = r"存档\战功兑换\31.bmp|存档\战功兑换\32.bmp|存档\战功兑换\33.bmp|存档\战功兑换\34.bmp|存档\战功兑换\35.bmp|存档\战功兑换\36.bmp|存档\战功兑换\37.bmp"
                for i in range(15):
                    is_get = self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 0, 0.1, 0, 0, 0)
                    if is_get == 1:
                        return res
                    is_get = self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 0, 0.1, 0, 0, 0)
                    if is_get == 1:
                        return res
                    res=self.dm.SearchPngClick(478, 652, 800, 701, path, 0.9, 12, 0.052, 6, 10, 10, is_wait=1)
                    if res==0:
                        path=r"存档\战功兑换\38.bmp"
                        self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 12, 0.052, 2, 10, 10, is_wait=1)
                        break
            elif res == 5:
                self.log.info("xxx")
                # 客昌丹
                self.dm.LeftClick(762, 683, 1)
                # 功法残页
                self.dm.LeftClick(675, 683, 1)

            elif res == 6:
                if self.publicData["主c"]["战功第5列选择"] == "攻击":
                    path = r"存档\战功兑换\51.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 8, 0.052, 1, 10, 10, is_wait=1)
                elif self.publicData["主c"]["战功第5列选择"] == "外功":
                    path = r"存档\战功兑换\52.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 8, 0.052, 1, 10, 10, is_wait=1)
                elif self.publicData["主c"]["战功第5列选择"] == "内功":
                    path = r"存档\战功兑换\53.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 8, 0.052, 1, 10, 10, is_wait=1)
                else:
                    path = r"存档\战功兑换\51.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 8, 0.052, 1, 10, 10, is_wait=1)
                    path = r"存档\战功兑换\52.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                    path = r"存档\战功兑换\53.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                    path = r"存档\战功兑换\54.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                    path = r"存档\战功兑换\55.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                    path = r"存档\战功兑换\56.bmp"
                    self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
            elif res in [7,8]:
                for i in range(5):
                    self.dm.LeftClick(500 + i * 44, 679, 1)
                    time.sleep(0.1)
                    self.dm.LeftClick(500 + i * 44, 679, 1)
                self.data["当前战功兑换层数"]=9
            elif res in [9,10]:
                self.BuyAllGoods(dealy=0.1)
            elif res in [11,12]:
                self.BuyAllGoods(dealy=0.1)
        return 0


    # 高昌 如果在高昌不进行其他操作
    def JoinGaoChangCheck(self, n):
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            self.data["是否在高昌"] = False
        if self.data["是否在高昌"] is False:
            res = self.JoinGaoChang(n)
            self.dm.KeyPressChar("f1", num=2)
            is_get = self.dm.SearchPngClick(100, 20, 1100, 520, "主线\门派战功兑换.bmp", 0.8, 1, 0.3, 0, 0, 0)
            if is_get == 1:
                self.data["是否在高昌"] = False


    # 高昌
    def JoinGaoChang(self, n):
        self.log.info("开始进高昌")
        is_get = self.AccessHomeNPC("文秀")
        if is_get <= 0:
            return -1
        time.sleep(0.5)
        self.publicData["是否回门派过"] = False
        self.publicData["是否回家过"] = False
        res = self.dm.SearchPngClick(478, 652, 837, 701, "主线\高昌外区.bmp|主线\高昌深处.bmp|主线\文秀_大队集结令.bmp|主线\文秀_兑换融金石.bmp", 0.9, 10, 0.3, 0, 10, 10)
        if res == 0:
            return -1
        if n == 1:
            res=self.dm.SearchPngClick(478, 652, 837, 701, "主线\高昌外区.bmp", 0.9, 50, 0.3, 2, 10, 10, is_wait=1)
            time.sleep(1)
            for i in range(2):
                is_get = self.DotaCheckMoveAttack(14, 643, 800, 560,step=0.3,n=6)
                if is_get == 1:
                    self.data["是否在高昌"] = True
                    return 1
                else:
                    time.sleep(1)
        if n == 2:
            self.dm.SearchPngClick(478, 652, 837, 701, "主线\高昌深处.bmp", 0.9, 50, 0.3, 2, 10, 10, is_wait=1)
            for i in range(2):
                time.sleep(0.5)
                is_get =  self.DotaCheckMoveAttack(42, 660, 566, 209,step=0.3,n=6)
                if is_get == 1:
                    self.data["是否在高昌"] = True
                    return 1
                time.sleep(0.5)
        return -1

    # 拿洗髓经
    def GetMarrowCleansingSutra(self):
        for i in range(5):
            is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp|主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp|主线\洗髓经_垃圾.bmp|主线\洗髓经_垃圾2.bmp", 0.9, 20, 0.1, 0, 0, 0)
            if is_get==1:
                is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp", 0.9, 1, 0, 1, 5, 5)
                if is_get!=1:
                    is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp", 0.9, 1, 0, 1, 5, 5)
                    if is_get != 1:
                        self.dm.LeftClick(550, 400, 1)


                is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 35, 0.1, 1, 20, 90,is_wait=1)
                if is_get==1:
                    break
    # 拿洗髓经
    def GetMarrowCleansingSutraFast(self):
        for i in range(1):
            is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp|主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp|主线\洗髓经_垃圾.bmp|主线\洗髓经_垃圾2.bmp", 0.9, 20, 0.1, 0, 0, 0)
            if is_get==1:
                is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_极品.bmp|主线\洗髓经_极品2.bmp", 0.9, 1, 0, 1, 5, 5)
                if is_get!=1:
                    is_get = self.dm.SearchPngClick( 405, 330, 885, 475,"主线\洗髓经_普通.bmp|主线\洗髓经_普通2.bmp", 0.9, 1, 0, 1, 5, 5)
                    if is_get != 1:
                        self.dm.LeftClick(550, 400, 1)


                is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 35, 0.1, 1, 20, 90,is_wait=1)
                if is_get==1:
                    break
    def CompleteMainTask1(self, n, t):
        self.log.info("开始推主线")
        self.dm.KeyPressChar("f1",num=2)
        t=t*10
        step=0.1
        self.GetMarrowCleansingSutraFast()
        path = r"主线\00_1饿狼传说1.bmp|主线\00_2饿狼传说2.bmp|主线\00_3饿狼传说3.bmp|主线\01_1破敌先锋.bmp|主线\02选择.bmp|主线\02_2英雄救美.bmp|主线\03_1掩护百姓.bmp|主线\04_1营救文秀.bmp|主线\05_1破除巫术.bmp|主线\06_1再战鬼巫.bmp|主线\06_2虎军卧底.bmp|主线\07_1大闹敌宴.bmp"
        path = self.dm.GetPicAbsPath(path)
        x, y, res = self.dm.FindPic(1195, 91, 1275, 106, path, "000000", 0.95, 0)
        if x > 0 and y > 0:
            if res >n:
                return  res
            n = res
        else:
            # 掉线等原因没找到
            return -1
        self.log.info(n)
        self.dm.SearchPngClick(1135, 100, 1280, 326, "主线\立即前往.bmp", 0.9, 1, 0.03, 1, 20, 5)
        self.publicData["是否回家过"] = False
        time.sleep(0.5)
        if n == 0 or n == 1 or n == 2:
            time.sleep(0.2)
            self.DotaBlink(78, 642, 683, 163,n=2)
            res = self.ExchangeMilitaryAchievements(2,isGoHome=False)
            time.sleep(1)
            for i in range(int(t/2)):
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\00_1饿狼传说1.bmp|主线\00_2饿狼传说2.bmp|主线\00_3饿狼传说3.bmp", 0.9, 1, step*2)
                if is_get==0:
                    self.dm.SearchPngClick(100, 100, 1200, 400, self.publicData["门派挑战选择配置"], 0.8, 3, 0.5, 1, 20, 20)
                    break
                else:
                    self.DotaAttack(78, 642, 583, 163)
        elif n == 3:
            self.dm.SearchPngClick(100, 100, 1200, 400, self.publicData["门派挑战选择配置"], 0.8, 3, 0.5, 1,
                                   20, 20)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\01_1破敌先锋.bmp", 0.9, 0.5*t, step)
            if is_get == 0:
                time.sleep(0.1)
                self.GetMarrowCleansingSutra()
            else:
                self.DotaAttack(0,0,640,360)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\01_1破敌先锋.bmp", 0.9, 0.5*t, step)
                if is_get == 0:
                    time.sleep(0.1)
                    self.GetMarrowCleansingSutra()
        elif n == 4:
            self.dm.WaitPngDisappear(1195,91,1275,106, r"主线\02选择.bmp", 0.9, 1, 0.03, 1, 37, 108)
            self.data["最近一次大还丹时间"] = time.time()
        elif n == 5:
            for i in range(4):
                self.DotaBlink(0, 0, 640, 85)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\02_2英雄救美.bmp", 0.9, t/4, step)
                if is_get==0:
                    self.GetMarrowCleansingSutra()
                    break
        elif n == 6:
            self.DotaBlink(0, 0, 720, 85,n=2)
            # res = self.ExchangeMilitaryAchievements(2, isGoHome=False)
            is_get = self.dm.SearchPngClick(958, 461, 1275, 651, r"主线\香囊.bmp", 0.9, 1, 0, 5, 0, 0)
            is_get = self.dm.SearchPngClick(958, 461, 1275, 651, r"主线\香囊.bmp", 0.9, 1, 0, 2, 0, 0)
            self.data["最近一次小师妹时间"] = time.time()
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\03_1掩护百姓.bmp", 0.9, t, step)
            time.sleep(0.1)
            if is_get == 0:
                self.GetMarrowCleansingSutra()
        elif n == 7:
            self.DotaBlink(0, 0, 257, 557,2)
            if self.publicData["基础配置"]["角色"] == "主c"  and self.publicData["主c"]["暂停次数"] >0:
                self.data["最近一次暂停时间"]=300.0
                self.DelayingEnemy()
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\04_1营救文秀.bmp", 0.9, t/2, step)
            if is_get==1:
                self.DotaAttack(0, 0, 257, 557)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\04_1营救文秀.bmp", 0.9, t / 2, step)
        elif n == 8:
            time.sleep(0.3)
            self.DotaBlink(0, 0,107, 337,3)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\05_1破除巫术.bmp", 0.9, t, step)
            if is_get==1:
                self.DotaAttack(0, 0, 107, 337)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\05_1破除巫术.bmp", 0.9, t, step)
            time.sleep(0.1)
            if is_get == 0:
                self.GetMarrowCleansingSutra()
        elif n == 9:
            time.sleep(0.5)
            self.DotaBlink(40, 612, 750, 419,5)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\06_1再战鬼巫.bmp", 0.9, t, step)
            if is_get==1:
                self.DotaAttack(39, 612, 779, 419)
            else:
                self.GetMarrowCleansingSutra()
        elif n == 10:
            is_get = self.dm.SearchPngClick(722, 623, 837, 705, "存档\空装备栏.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(634, 585, 1)
                self.GetMarrowCleansingSutra()
            else:
                time.sleep(0.319)
                self.AccessNPC(33, 612,734, 365)
                self.dm.LeftClick(502,682,1)

        else:
            return 11
        if n>9:
            self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 5, 5, 5,is_wait=1)
        return n

    def HuanglingChoose(self):
        random_int = random.randint(1, 10000000)

        self.dm.DebugScreen(r"黄陵\%s黄陵"%random_int)
        self.dm.DebugScreen(r"黄陵\%s左边"%random_int, 518, 481, 559, 522)
        is_choose=False
        res = self.dm.SearchPngClickEXn(400, 450, 670, 530, self.data["黄陵卷轴全路径"], 0.8, 10, 0.1, 0, 0, 0)
        if res[0] != -1:
            self.log.info("是卷轴")
            is_choose = self.HuanglingScrollChoose(random_int)
            if is_choose:
                return 1

        else:
            self.log.info("是装备")
            is_choose = self.HuanglingEquipmentChoose(random_int)
            if is_choose:
                return 1

        self.log.info("不满足条件不选")
        self.dm.LeftClick(825, 300, 2)
        self.dm.MoveTo(336, 658)
        return 0


    # 卷轴选择
    # res -1 未选择 0 是卷轴但不拿取  1 拿取
    def HuanglingScrollChoose(self,randomId=0):
        self.log.info("开始检查拿去图纸")
        if randomId==0:
            randomId = random.randint(1, 10000000)
        tmp_list=[]
        for i in self.publicData["存档"]["黄陵选择"]["图纸"]:
            name=i[0]
            lv=i[1]
            if self.data["黄陵层数"]< lv:
                continue
            else:
                tmp_list.append(self.publicData["图片映射"][name])
        self.log.info(tmp_list)
        if len(tmp_list)==0:
            return False
        path = "|".join(tmp_list)
        res = self.dm.SearchPngClickEXn(400, 450, 670, 530, path, 0.8, 10, 0.1, 0, 0, 0)
        if "斗篷" in res[1]:
            self.dm.MoveTo(540, 498)
            time.sleep(0.5)
            self.dm.DebugScreen(r"黄陵\%s黄陵斗篷"%randomId)
            is_get = self.dm.SearchPngClick(400, 350, 800, 620, "存档\黄陵\军心.bmp", 0.9, 1, 0, 0, 0, 0)

            if is_get==1 or  self.publicData["存档"]["斗篷只拿军心"] is False:
                self.log.info("拿斗篷卷轴 出货了")
                self.dm.LeftClick(580, 300, 2)
                return True
            else:
                self.log.info("不拿取铁骨卷轴")
                return False
        elif res[0] != -1:
            self.log.info("找到了非斗篷需要的卷轴 出货了")
            self.dm.LeftClick(580, 300, 2)
            return True
        else:
            self.log.info("找到了不需要的卷轴")
            return False
    @staticmethod
    def get4NumStr(text):
        for i in range(4):
            if len(text) < 4:
                text = text + "0"
            else:
                break
        return  int(text)

    # 装备选择
    # res -1 未选择 0 是卷轴但不拿取  1 拿取
    def HuanglingEquipmentChoose(self, randomId=0):

        self.log.info("开始检查装备满足属性")

        if randomId==0:
            randomId = random.randint(1, 10000000)
        file_path, x, y = self.dm.FindPicExS(515, 480, 560, 525, self.data["黄陵装备"], "000000", 0.95)
        if x<0 or y<0:
            self.log.info("装备图片不全")
            self.dm.DebugScreen(r"黄陵\%s左边无记录" % randomId, 518, 481, 559, 522)
            self.dm.MoveTo(540, 498)
            time.sleep(1)
            self.dm.DebugScreen(r"黄陵\%s左边无记录全" % randomId)
            return False
        name = os.path.basename(file_path).replace(".bmp", "").rstrip("0123456789")
        self.log.info(name)
        tmp = self.publicData["存档"]["黄陵选择"]["装备"]
        if name not in tmp:
            self.log.info("不是配置的装备")
            return  False

        self.dm.MoveTo(540, 498)
        time.sleep(0.5)
        self.log.info("查看装备属性")
        for i in range(10):
            res, x_0, y_0 = self.dm.FindPicEx(570, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\附加属性.bmp"), "", 1.0)
            if res != -1:
                if i<10:
                    break
                else:
                    self.log.info("查看装备属性失败")
                    return False
            else:
                time.sleep(0.1)
                self.dm.MoveTo(540, 498)

        time.sleep(0.3)
        self.dm.DebugScreen(r"黄陵\%s黄陵属性" % randomId)
        res, x_0, y_0 = self.dm.FindPicEx(570, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\附加属性.bmp"), "", 1.0)
        res, x_m, y_max = self.dm.FindPicEx(584, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\属性栏底部.bmp"), "", 1.0)
        y_base = y_0 + 21
        self.log.info("查看装备每条属性")
        for i in range(13):
            y1 = y_base + (i * 16)
            y2 = y_base + (i * 16) + 12
            if y2 > y_max:
                break
            x, y, res = self.dm.FindColor(584, y1 - 2, 780, y2 + 2, "bf1a18-050505", 1.0, 0)
            if res == 1:
                attr, x, y = self.dm.FindPicExS(582, y1, 780, y2, self.data["黄陵属性"], "000000", 0.95)
                attr = os.path.basename(attr).replace(".bmp", "")
                num = self.OcrHuangLingRedNum(584, y1, 780, y2, 0.95)
                num= self.get4NumStr(num)
                self.log.info(num)
                self.dm.DebugScreen(r"黄陵\%s_%s黄陵属性_%s_%s_" % (randomId, i, attr, num), 584, y1, 780, y2)
                for item in self.publicData["存档"]["黄陵选择"]["装备"][name]:
                    if item[0]!=attr or self.data["黄陵层数"]<item[2]:
                        continue
                    else:
                        if  num >=item[1]:
                            self.dm.LeftClick(580, 300, 2)
                            self.log.info("装备%s 出货了 %s %s "%(name,item[0],item[1]))
                            return True
        return False

    def UseSkillBook(self, n=5):
        self.log.info("使用技能书")
        is_get = self.dm.SearchPngClick(1000, 450, 1280, 650, "存档\功法残页不带数量.bmp", 0.9, 1, 0, 2, 5, 5)
        if is_get == 1:
            is_get = self.dm.SearchPngClick(367, 453, 927, 527, "存档\技能升级.bmp", 0.8, 6, 0.5, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(484, 494, n)
        else:
            return
        self.dm.LeftClick(self.safeX,self.safeY,n=2)
        self.dm.LeftClick(self.safeX, self.safeY,n=1)

    # 自动释放q
    def AutoQ(self,tag=""):
        self.dm.KeyPressChar("f1",num=2)
        self.GoSect()
        self.MoveMouseSafe()
        time.sleep(0.5)
        self.log.info("开起自动施法")

        for i in range(3):
            time.sleep(0.2)
            dm_ret = self.dm.Capture(419, 633, 449, 663, tag + "q.bmp")
            self.log.info(dm_ret)
            time.sleep(0.2)
            is_get = self.dm.SearchPngClick(415, 630, 455, 670, tag+"q.bmp", 0.95, 10, 0.05, 0, 0, 0)
            #self.dm.DebugScreen("aaaa")
            if is_get==1:
                self.dm.RightClick(432, 647, 1)
            else:
                return 1
        return 0

    def MoveMouseSafe(self):
        self.dm.MoveTo(self.safeX,self.safeY)
    def OcrHuangLingRedNum(self,x1,y1,x2,y2,sim=1.0):
        self.dm.UseDict(2)
        res=self.dm.dm.Ocr(x1,y1,x2,y2, "#77-10",sim)
        self.log.info(res)
        return res
    # 论剑
    def OcrLunJianNum(self):
        self.dm.UseDict(1)
        for i in range(3):
            res = self.dm.dm.Ocr(665, 138, 730, 162, "#255-30", 1.0)
            self.log.info(res)
            if res != "":
                return int(res)

        return -1
    # 银
    def OcrSuiYinNum(self):
        self.dm.UseDict(0)
        res = self.dm.dm.Ocr(979, 697, 1042, 718, "#240-30", 1.0)
        self.log.info(res)
        if res == "":
            return -1
        return int(res)
    # 战功
    def OcrZhanGongNum(self):
        self.dm.UseDict(0)
        res = self.dm.dm.Ocr(1086, 697, 1149, 718, "#240-30", 1.0)
        self.log.info(res)
        if res == "":
            return -1
        return int(res)

    # 古币
    def OcrGuBiNum(self):
        self.dm.UseDict(0)
        res = self.dm.dm.Ocr(1193, 697, 1256, 718, "#240-30", 1.0)
        self.log.info(res)
        if res == "":
            return -1
        return int(res)

    def OcrCarryDeadNum(self):
        self.dm.UseDict(3)
        res = self.dm.dm.Ocr(33,55,59,80,"e85144-303030",1.0)
        self.log.info(res)
        if res == "":
            return -1
        self.log.info("xxxxxxxxx复活xxxxxxxxxxxxxaaasasdfdsa")
        return int(res)


# start get pic
    def GetBackpackPic(self,tag="背包"):
        x0 = 1009
        y0 = 481
        for i in range(5):
            for j in range(8):
                x1 = x0 + j * 33
                x2 = x1 + 26
                y1 = y0 + i * 33
                y2 = y1 + 26
                self.dm.DebugScreen("素材/%s%s%s" % (tag,i, j), x1=x1, x2=x2, y1=y1, y2=y2)
    def GetPublicBackpackPic(self,tag="公共仓库"):
        x0 = 1010
        y0 = 371
        for i in range(2):
            for j in range(8):
                x1 = x0 + j * 33
                x2 = x1 + 26
                y1 = y0 + i * 33
                y2 = y1 + 26
                self.dm.DebugScreen("素材/%s%s%s" % (tag,i, j), x1=x1, x2=x2, y1=y1, y2=y2)

    def Get9BossPic(self,path):
        random_int = random.randint(1, 10000000)
        x0 = 1009
        y0 = 481
        for i in range(5):
            for j in range(8):
                x1 = x0 + j * 33
                x2 = x1 + 26
                y1 = y0 + i * 33
                y2 = y1 + 26
                sx1=x1-3
                sy1=y1-3
                sx2=x2+3
                sy2=y2+3

                res=self.dm.SearchPngClick(sx1,sy1,sx2,sy2,path,0.99,1,0.1,0,0,0)
                if res==0:
                    self.log.info("有未记录的宝石")
                    self.dm.DebugScreen("宝石素材/%s_%s_%s背包图" % (random_int, i, j), x1=x1, x2=x2, y1=y1, y2=y2)
                    self.dm.MoveTo(x1+5,y1+5)
                    time.sleep(0.5)
                    self.dm.DebugScreen("宝石素材/%s_%s_%s详情图"% (random_int, i, j))
                    self.dm.RightClick(x1 + 5, y1 + 5, 1)
                    is_get = self.dm.SearchPngClick(900, 400, 1280, 700,self.data["放入公共仓库图片路径"],  0.9, 3, 0.5, 1, 5, 5)
                    if is_get!=0:
                        self.MoveMouseSafe()
                        time.sleep(0.5)
                        px0 = 1010
                        py0 = 371
                        for i in range(2):
                            for j in range(8):
                                px1 = px0 + j * 33
                                px2 = px1 + 26
                                py1 = py0 + i * 33
                                py2 = py1 + 26
                                is_get = self.dm.SearchPngClick(px1, py1, px2, py2, self.data["背包空图片路径"], 0.9, 1, 0.1, 0, 0, 0)
                                if is_get==0:
                                    self.dm.DebugScreen("宝石素材/%s_%s_%s仓库图" % (random_int, i, j), x1=px1, x2=px2, y1=py1, y2=py2)

    def GetBackpackPicLeft(self,tag="背包不带数量"):
        x0 = 1009
        y0 = 481
        for i in range(5):
            for j in range(8):
                x1 = x0 + j * 33
                x2 = x1 + 10
                y1 = y0 + i * 33
                y2 = y1 + 26
                self.dm.DebugScreen("素材/%s%s%s" % (tag,i, j), x1=x1, x2=x2, y1=y1, y2=y2)
    def GetBackpackPicUp(self,tag="背包不带数量"):
        x0 = 1009
        y0 = 481
        for i in range(5):
            for j in range(8):
                x1 = x0 + j * 33
                x2 = x1 + 26
                y1 = y0 + i * 33
                y2 = y1 + 10
                self.dm.DebugScreen("素材/%s%s%s" % (tag,i, j), x1=x1, x2=x2, y1=y1, y2=y2)
    def GetShopPicPart(self,tag="商人"):
        random_int = random.randint(1, 10000000)
        time.sleep(1.5)
        self.dm.DebugScreen(r"素材\%s%s0" % (tag,random_int))
        x1=485
        x2=516
        y1=664
        # y2=695
        y2=682
        for i in range(10):
            self.dm.DebugScreen(r"素材\%s%s%s" %(tag,i,random_int), x1+i*44, y1, x2+i*44, y2)
    def GetShopPicPart2(self,tag="商人"):
        random_int = random.randint(1, 10000000)
        time.sleep(1)
        self.dm.DebugScreen(r"素材\%s_0_%s_0" % (tag,random_int))
        x1=485
        x2=516
        y1=664
        # y2=695
        y2=682
        for i in range(10):
            self.dm.DebugScreen(r"素材\%s_%s_%s_1" %(tag,i,random_int), x1+i*44+18, y1, x2+i*44, y2)

    def GetNpcGoodPic(self,n=1,tag="npc"):
        random_int = random.randint(1, 10000000)
        time.sleep(0.1)
        self.dm.DebugScreen(r"素材\%s_%s_" % (tag, random_int))
        if n==2:
            x1 = 485
            x2 = 516
            y1 = 669
            y2 = 700
            for i in range(10):
                self.dm.DebugScreen(r"素材\%s_%s_%s_1_" % (tag,random_int,i), x1 + i * 44, y1, x2 + i * 44, y2)
            y1 = 629
            y2 = 660
            random_int = random.randint(1, 10000000)
            for i in range(10):
                self.dm.DebugScreen(r"素材\%s_%s_%s_2" % (tag,random_int,i), x1 + i * 44, y1, x2 + i * 44, y2)
        else:
            x1 = 485
            x2 = 516
            y1 = 664
            y2=695
            for i in range(10):
                self.dm.DebugScreen(r"素材\%s_%s_%s" % (tag,random_int,i), x1 + i * 44, y1, x2 + i * 44, y2)

    def GetXinMoPic(self):
        self.MoveMouseSafe()
        time.sleep(0.1)
        random_int = random.randint(1, 10000000)
        # self.dm.DebugScreen(r"素材\心魔%s1c"%random_int, 345, 195, 390, 207)
        # self.dm.DebugScreen(r"素材\心魔%s2c"%random_int, 600, 195, 645, 207)
        # self.dm.DebugScreen(r"素材\心魔%s3c"%random_int, 855, 195, 900, 207)
        # self.dm.DebugScreen(r"素材\心魔%s1d"%random_int, 288, 182, 448, 465)
        # self.dm.DebugScreen(r"素材\心魔%s2d"%random_int, 543, 182, 703, 465)
        # self.dm.DebugScreen(r"素材\心魔%s3d"%random_int, 798, 182, 958, 465)

        self.dm.DebugScreen(r"素材\心魔%s1c" % random_int, 345, 195, 390, 207)
        self.dm.DebugScreen(r"素材\心魔%s2c" % random_int, 600, 195, 645, 207)
        self.dm.DebugScreen(r"素材\心魔%s3c" % random_int, 855, 195, 900, 207)
        self.dm.DebugScreen(r"素材\心魔%s1d" % random_int, 288, 177, 448, 465)
        self.dm.DebugScreen(r"素材\心魔%s2d" % random_int, 543, 177, 703, 465)
        self.dm.DebugScreen(r"素材\心魔%s3d" % random_int, 798, 177, 958, 465)

    def GetHuangLingPic(self):
        random_int = random.randint(1, 10000000)

        self.dm.DebugScreen(r"黄陵\黄陵")
        self.dm.DebugScreen("黄陵\左边", 518, 481, 559, 522)

        for i in range(10):
            res, x_0, y_0 = self.dm.FindPicEx(570, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\附加属性.bmp"), "",
                                              1.0)
            if res !=-1:
                break
            else:
                time.sleep(0.1)
        time.sleep(0.5)
        self.dm.DebugScreen(r"黄陵\%s黄陵属性" % random_int)
        res, x_0, y_0 = self.dm.FindPicEx(570, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\附加属性.bmp"), "", 1.0)
        res, x_m, y_max = self.dm.FindPicEx(584, 0, 780, 720, self.dm.GetPicAbsPath(r"存档\属性栏底部.bmp"), "",  1.0)

        y_base = y_0 + 21
        for i in range(13):
            y1 = y_base + (i * 16)
            y2 = y_base + (i * 16) + 12
            if y2 > y_max:
                break

            x, y, res = self.dm.FindColor(584,y1-2,780,y2+2, "bf1a18-050505", 1.0, 0)
            if res ==1:
                file_path,x,y = self.dm.FindPicExS(582, y1, 780, y2, self.data["黄陵属性"], "000000",0.95)
                file_name=os.path.basename(file_path)
                num=self.OcrHuangLingRedNum(584, y1, 780, y2,0.95)
                self.dm.DebugScreen(r"黄陵\%s%s黄陵属性_%s_%s_" % (random_int,i,file_name,num), 584, y1, 780, y2)

    def GetWPic(self,tag="副功法"):
        random_int = random.randint(1, 10000000)
        time.sleep(0.5)
        self.dm.DebugScreen(r"素材\%s%s" %(tag,random_int), 462, 645, 485, 660)

    def GetArmPic(self):
        random_int = random.randint(1, 10000000)
        self.MoveSafe()
        time.sleep(0.5)
        self.dm.DebugScreen(r"武器\a1%s0" % random_int)
        self.dm.DebugScreen(r"武器\a1%s1" % random_int, 208, 226, 326, 240)
        self.dm.DebugScreen(r"武器\a1%s2" % random_int, 456, 226, 574, 240)
        self.dm.DebugScreen(r"武器\a1%s3" % random_int, 704, 226, 822, 240)
        self.dm.DebugScreen(r"武器\a1%s4" % random_int, 952, 226, 1070, 240)
        path=self.dm.GetPicAbsPath("主线\选武器绿宝玉空.bmp|主线\选武器绿宝玉.bmp|主线\选武器绿宝石空.bmp|主线\选武器绿宝石.bmp|主线\选武器蓝宝玉空.bmp|主线\选武器蓝宝玉.bmp|主线\选武器蓝宝石空.bmp|主线\选武器蓝宝石.bmp|主线\选武器红宝玉空.bmp|主线\选武器红宝玉.bmp|主线\选武器红宝石空.bmp|主线\选武器红宝石.bmp")
        x,y,res = self.dm.FindPic(178, 244, 356, 963,path ,"000000", 0.9)
        # if x>0 and y>0:
        #     self.dm.DebugScreen(r"武器\a2%s1" % random_int, 178, 195, 356, y)
        # else:
        #     self.dm.DebugScreen(r"武器\a2%s1" % random_int, 178, 195, 356, 438)
        # x, y, res = self.dm.FindPic(426, 244, 604, 963, path,"000000", 0.9)
        # if x > 0 and y > 0:
        #     self.dm.DebugScreen(r"武器\a2%s2" % random_int, 426, 195, 604, y)
        # else:
        #     self.dm.DebugScreen(r"武器\a2%s2" % random_int, 426, 195, 604, 438)
        # x, y, res = self.dm.FindPic(674, 244, 852, 963, path,"000000", 0.9)
        # if x > 0 and y > 0:
        #     self.dm.DebugScreen(r"武器\a2%s3" % random_int, 674, 195, 852, y)
        # else:
        #     self.dm.DebugScreen(r"武器\a2%s3" % random_int, 674, 195, 852, 438)
        # x, y, res = self.dm.FindPic(922, 244, 1100, 963, path,"000000", 0.9)
        # if x > 0 and y > 0:
        #     self.dm.DebugScreen(r"武器\a2%s4" % random_int, 922, 195, 1100, y)
        # else:
        #     self.dm.DebugScreen(r"武器\a2%s4" % random_int, 922, 195, 1100, 438)
        # 截取图片有差异
        if random_int > -1:
            return 1
        # self.dm.DebugScreen(r"武器\a2%s1" % random_int, 180, 195, 354, 460)
        # self.dm.DebugScreen(r"武器\a2%s2" % random_int, 428, 195, 602, 460)
        # self.dm.DebugScreen(r"武器\a2%s3" % random_int, 676, 195, 850, 460)
        # self.dm.DebugScreen(r"武器\a2%s4" % random_int, 924, 195, 1098, 460)

    # 绝世神兵 只有2个
    def GetArm2Pic(self):
        random_int = random.randint(1, 10000000)
        time.sleep(0.1)
        self.dm.DebugScreen(r"武器\a1%s0" % random_int)

        self.dm.DebugScreen(r"武器\a1%s2" % random_int, 456, 226, 574, 240)
        self.dm.DebugScreen(r"武器\a1%s3" % random_int, 704, 226, 822, 240)

        path = self.dm.GetPicAbsPath(
            "主线\选武器绿宝玉空.bmp|主线\选武器绿宝玉.bmp|主线\选武器绿宝石空.bmp|主线\选武器绿宝石.bmp|主线\选武器蓝宝玉空.bmp|主线\选武器蓝宝玉.bmp|主线\选武器蓝宝石空.bmp|主线\选武器蓝宝石.bmp|主线\选武器红宝玉空.bmp|主线\选武器红宝玉.bmp|主线\选武器红宝石空.bmp|主线\选武器红宝石.bmp")
        x, y, res = self.dm.FindPic(178, 244, 356, 963, path, "000000", 0.9)

        x, y, res = self.dm.FindPic(426, 244, 604, 963, path, "000000", 0.9)
        if x > 0 and y > 0:
            self.dm.DebugScreen(r"武器\a2%s2" % random_int, 426, 195, 604, y)
        else:
            self.dm.DebugScreen(r"武器\a2%s2" % random_int, 426, 195, 604, 438)
        x, y, res = self.dm.FindPic(674, 244, 852, 963, path, "000000", 0.9)
        if x > 0 and y > 0:
            self.dm.DebugScreen(r"武器\a2%s3" % random_int, 674, 195, 852, y)
        else:
            self.dm.DebugScreen(r"武器\a2%s3" % random_int, 674, 195, 852, 438)
        x, y, res = self.dm.FindPic(922, 244, 1100, 963, path, "000000", 0.9)

    def GetArmRecognizeLordPic(self):
        self.log.info("开始截图认主武器")
        random_int = random.randint(1, 10000000)

        for x in range(10):
            self.dm.KeyPressChar("f5")
            time.sleep(1)
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539,
                                            "主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                            0.9, 1, 0.3, 0, 0, 0)
            if is_get == 1:
                break
        self.dm.DebugScreen(r"武器镶嵌\%sA" % random_int)
        x0 ,y0 =185 ,274
        for i in range(3):
            for j in range(6):
                x1 = x0 + j*162
                y1 = y0 + i*75
                x2 = x1 + 24
                y2 = y1 + 24
                self.dm.DebugScreen(r"武器镶嵌\%sB%s%s" % (random_int,i,j),x1,y1,x2,y2)

        for i in range(10):
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539,
                                            r"主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                            0.9,
                                            1, 0.3, 0, 0, 0)
            if is_get == 1:
                self.dm.KeyPressChar("f5")
                time.sleep(3)
            else:
                break
    def RGemPurple(self):
        self.log.info("准备R七级紫宝石")
        self.MoveSafe()
        time.sleep(0.1)
        now = time.time()
        if now - self.data["最近一次R宝石"] < 60.0:
            self.log.info("最近一次R宝石<60s")
            return 0
        self.log.info("开R七级紫宝石")
        self.data["最近一次R宝石"] = now
        path = self.data["宝石7级无紫"]
        self.log.info(path)
        time.sleep(0.1)
        res, x, y = self.dm.FindPicExS(992, 460, 1280, 650, path, "000000", 0.95)
        if res !=- 1:
            self.log.info(res)
            self.dm.DragFast(x+5,y+5,1023,497)

        else:
            self.log.info("背包里没有7级宝石")

            res, x, y = self.dm.FindPicExS(1000, 350, 1280, 450, path, "000000", 0.95)
            if  res !=- 1:
                self.dm.DragFast(x + 5, y + 5, 1026, 556)
                self.log.info("找到宝石 %s " % res)
                res = self.GetRelativePath(res, "pic")
                self.log.info("宝石相对路径 %s " % res)
                self.MoveSafe()
                time.sleep(1)
            else:
                self.log.info("公共仓库里没有7级宝石")
                return 0
        res = self.dm.FindPicExs(992, 460, 1280, 650, path, "000000", 0.95)
        if len(res) >= 1:
            self.log.info(res)
            self.dm.DragFast(res[0][1], res[0][2], 1023, 497)
            time.sleep(1)
        for i in range(1):
            self.dm.KeyPressChar("f2")
            self.dm.KeyPressChar("f2")
            self.dm.KeyPressChar("e")
            is_get = self.dm.SearchPngClick(300, 400, 1000, 530, r"主线\8级宝石重铸背景.bmp|主线\7级宝石重铸背景.bmp|主线\6级宝石重铸背景.bmp|主线\5级宝石重铸背景.bmp|主线\4级宝石重铸背景.bmp|主线\3级宝石重铸背景.bmp", 0.95, 20, 0.1, 2, 0, 0)
            if is_get==0:
                return 0
            is_get=self.dm.SearchPngClick(300,100,1000,300,r"主线\万古紫.bmp",0.9,1,0.1,2,0,0)
            if is_get!=1:
                self.dm.LeftClick(462,310,n=2)
        for i in range(3):
            is_get = self.dm.SearchPngClick(500, 400, 800, 437, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 10, 0.3, 1, 5, 5)
            if is_get==1:
                self.data["最近一次R宝石"] = now+120.0
                break
            else:
                self.dm.LeftClick(462, 310, n=2)
                is_get = self.dm.SearchPngClick(500, 400, 800, 437, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 10,
                                                0.3, 1, 5, 5)
                if is_get==1:
                    self.data["最近一次R宝石"] = now + 120.0
                break
        time.sleep(1)
        self.HandInGem(path=r"宝石\7级宝石万古紫.bmp")
        self.log.info("准备R七级紫宝石结束")


    # 进皇陵
    def ImperialMausoleumCarrayEnter(self):
        for i in range(3):
            self.AccessNPC(73, 660, 800, 312)
            self.dm.LeftClick(500, 680, 1)
            is_get = self.dm.SearchPngClick(500, 400, 650, 435, "存档\黄陵确认.bmp", 0.8, 10, 0.5, 1, 60, 10, is_wait=1)
            if is_get == 1:
                self.publicData["系统数据"]["皇陵次数"] += 1
                break
        self.dm.KeyPressChar("f1")
        self.dm.KeyPressChar("f1")
        res = self.DotaCheckMoveAttack(93, 649, 439, 257,step=0.3)
        if res == 1:
            return res
        time.sleep(1)
        return self.DotaCheckMoveAttack(93, 649, 439, 257,step=0.3)


    # 进入黄陵
    def ImperialMausoleumEnter(self):
        is_get = self.dm.SearchPngClick(500, 400, 650, 435, "存档\黄陵确认.bmp", 0.8, 3, 0.5, 1, 10, 10)
        if is_get == 1:
            self.dm.KeyPressChar("f1",num=2)
            self.SurpriseDropConfirm()  # 论剑会弹
            self.DotaAttack(94, 650, 515, 455)
            time.sleep(1)
            self.DotaAttack(94, 650, 515, 455)
            self.publicData["系统数据"]["皇陵次数"] += 1
            return 1


    def SellingCheats(self,path):
        res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, path, "000000", 0.9)
        if x > 0 and y > 0 :
            self.log.info("开始售卖%s"%path)
            self.dm.RightClick(x + 5, y + 5, 1)
            time.sleep(0.5)
            is_get = self.dm.SearchPngClick(900, 400, 1280, 720,
                                            "存档\出售全部秘籍.bmp|存档\出售全部秘籍1.bmp|存档\出售全部秘籍2.bmp|存档\出售全部秘籍3.bmp",
                                            0.9, 15, 0.1, 1, 5, 5)

    def CheckFloor(self):
        self.log.info("开始检查玩家楼层")
        site_list=[[20, 686],[37, 686]]
        path = "主线\门派游商.bmp"
        path2 = r"NPC选项\寻宝低级.bmp|NPC选项\寻宝低级10.bmp|NPC选项\寻宝中级.bmp|NPC选项\寻宝中级10.bmp|NPC选项\寻宝高级.bmp|NPC选项\寻宝高级10.bmp|NPC选项\寻宝超级10.bmp|NPC选项\寻宝低级X.bmp|NPC选项\寻宝低级10X.bmp|NPC选项\寻宝中级X.bmp|NPC选项\寻宝中级10X.bmp|NPC选项\寻宝高级X.bmp|NPC选项\寻宝高级10X.bmp|NPC选项\寻宝超级10X.bmp"
        for n in range(len(site_list)):
            self.dm.LeftClick(site_list[n][0], site_list[n][1], 2)
            for i in range(3):
                is_get = self.dm.SearchPngClick(100, 20, 1100, 520, path, 0.8, 3, 0.3, 1, 25, 40)
                if is_get !=1:
                    continue
                time.sleep(0.5)
                is_get = self.dm.SearchPngClick(360, 620, 460, 690, r"存档\npc头像.bmp", 0.8, 1, 0.1, 0, 0, 0)
                if is_get != 1:
                    continue

                is_get = self.dm.SearchPngClick(474, 619, 921, 707, path2, 0.8, 10, 0.1, 0, 0, 0)
                if is_get != 1:
                    continue
                self.data["玩家楼层"] = n+1
                self.log.info(self.data["玩家楼层"])
                return n+1
        self.data["玩家楼层"] = -1
        self.log.info(self.data["玩家楼层"])
        return -1
    # 辅助抽奖
    def SupDrawGem(self):
        start_time=time.time()
        self.log.info("检查辅助抽宝石")
        if self.OcrSuiYinNum() < 120000:
            self.log.info("钱不够跳过")
            return

        if self.data["玩家楼层"] <1:
            self.log.info("没有获取到玩家楼层 跳过")
            return
        if self.data["辅助抽宝石时间"] < 150.0 :
            return 0
        now = time.time()
        if now - self.data["辅助抽宝石时间"] < 30.0:
            return 0
        self.log.info("辅助抽宝石")
        a1 =time.time()
        res=self.AccessSiteNPC("游商",floor=self.data["玩家楼层"]) # 2.5s+
        a2 =time.time()
        self.log.info("rrr%s|%s"%(a1-start_time,a2-start_time))
        if res == 1:
            self.data["辅助抽宝石时间"] = now
            a3 = time.time()
            for i in range(8):
                is_get = self.dm.SearchPngClick(474, 619, 921, 707, r"NPC选项\寻宝中级10.bmp", 0.8, 1, 0, 2, 5, 5)
                if i%3==0:
                    self.SynthesisGemByLvs([2], handIn=True)
                self.SurpriseDropConfirm()
                time.sleep(0.1)

            a4 = time.time()
            self.log.info("rrr%s|%s"%(a3-start_time,a4-start_time))

            self.log.info("抽宝石合成")
            self.dm.KeyPressChar("f1",num=2)
            a5 = time.time()
            self.SynthesisGemByLvs([2, 3, 4, 5], handIn=True)
            time.sleep(0.1)
            a6 = time.time()
            self.log.info("rrr%s|%s"%(a5-start_time,a6-start_time))


    # 战功兑换层数
    def SupExchangeMilitaryAchievements(self,n):
        self.log.info("检查辅助兑换战功")
        if self.data["玩家楼层"] < 1:
            self.log.info("没有获取到玩家楼层 跳过")
            return
        if self.data["辅助兑换战功时间"] < 150.0 :
            return 0
        now = time.time()
        if now - self.data["辅助兑换战功时间"] < 30.0:
            return 0
        self.log.info("辅助兑换战功")
        if self.data["当前战功兑换层数"]>n:
            return 1

        is_get=self.AccessSiteNPC("战功兑换",floor=self.data["玩家楼层"])
        if is_get>0:
            self.data["辅助兑换战功时间"]=time.time()
            time.sleep(0.2)
            path = r"存档\战功兑换\第1层0.bmp|存档\战功兑换\第1层1.bmp|存档\战功兑换\第2层0.bmp|存档\战功兑换\第3层0.bmp|存档\战功兑换\第3层1.bmp|存档\战功兑换\第4层0.bmp|存档\战功兑换\第5层0.bmp|存档\战功兑换\第6层0.bmp|存档\战功兑换\第6层1.bmp|存档\战功兑换\第7层0.bmp|存档\战功兑换\第7层1.bmp|存档\战功兑换\第7层2.bmp|存档\战功兑换\第7层3.bmp"
            path = self.dm.GetPicAbsPath(path)
            x, y, res = self.dm.FindPic(475, 651, 919, 704, path, "000000", 0.9, 0)
            if res > n:
                self.data["当前战功兑换层数"]=res
                self.log.info("战功兑换结束")
                return 1
            if res==-1 and self.publicData["基础配置"]["模式"]=="普通":
                is1=self.dm.SearchPngClick(336, 400, 470, 712, r"存档\战功兑换头像.bmp", 0.9, 0, 0, 0, 0, 0)
                is2=self.dm.SearchPngClick(474, 650, 921, 701, r"存档\npc空白.bmp", 0.95, 0, 0, 0, 0, 0)
                if is1==1 and is2==1:
                    self.data["当前战功兑换层数"] = 9
                    return 1
            self.data["当前战功兑换层数"] = res
            self.log.info("当前战功兑换层数%s"%res)
            if res in [0,1]:

                path1 = r"存档\战功兑换\11.bmp|存档\战功兑换\12.bmp|存档\战功兑换\13.bmp|存档\战功兑换\14.bmp|存档\战功兑换\15.bmp|存档\战功兑换\16.bmp|存档\战功兑换\17.bmp"
                path2=r"存档\战功兑换\18.bmp"
                for i in range(15):
                    self.MoveSafe()
                    result=self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 2, 0.052, 6, 10, 10, is_wait=1)
                    if result==0:
                        self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 10, 0.052, 6, 10, 10, is_wait=1)
                        break
            elif res == 2:
                path = r"存档\战功兑换\26.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 12, 0.052, 2, 10, 10, is_wait=1)
            elif res in [3,4]:
                path = r"存档\战功兑换\31.bmp|存档\战功兑换\32.bmp|存档\战功兑换\33.bmp|存档\战功兑换\34.bmp|存档\战功兑换\35.bmp|存档\战功兑换\36.bmp|存档\战功兑换\37.bmp"
                for i in range(15):
                    res=self.dm.SearchPngClick(478, 652, 800, 701, path, 0.9, 12, 0.052, 6, 10, 10, is_wait=1)
                    if res==0:
                        path=r"存档\战功兑换\38.bmp"
                        self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 12, 0.052, 2, 10, 10, is_wait=1)
                        break
            elif res == 5:
                self.log.info("xxx")
                # 客昌丹
                self.dm.LeftClick(762, 683, 1)
                # 功法残页
                self.dm.LeftClick(675, 683, 1)

            elif res == 6:
                path = r"存档\战功兑换\51.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                path = r"存档\战功兑换\52.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                path = r"存档\战功兑换\53.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                path = r"存档\战功兑换\54.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                path = r"存档\战功兑换\55.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
                path = r"存档\战功兑换\56.bmp"
                self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 4, 0.052, 1, 10, 10, is_wait=1)
            elif res in [7,8]:
                for i in range(5):
                    self.dm.LeftClick(500 + i * 44, 679, 1)
                    time.sleep(0.1)
                    self.dm.LeftClick(500 + i * 44, 679, 1)
                self.data["当前战功兑换层数"]=9
            elif res in [9,10]:
                self.BuyAllGoods(dealy=0.1)
            elif res in [11,12]:
                self.BuyAllGoods(dealy=0.1)

        return 0

    def pauseGame(self):
        self.log.info("开始打断游戏线程")
        try:
            self.publicData["obj"]["game"].CustomPause()
        except SystemExit:
            self.log.info("调用Pause暂停运行")

    def goonGame(self):
        self.log.info("开始恢复游戏线程")
        self.publicData["obj"]["game"].CustomGoOn()